Dynamic Web Application runs with Eclipse but not in Tomcat

how to create dynamic web project in eclipse with tomcat
how to run web application in eclipse using tomcat
how to deploy web application in tomcat using eclipse
unable to add maven project to tomcat server in eclipse
how to run project on tomcat server in eclipse
run on server not showing in eclipse
how to create web application in eclipse using tomcat
add apache tomcat 8 to eclipse

I have been working on a small application, mostly as a learning exercise.

I have been introducing new things in stages. I had it working up to adding Struts 2.

Now, I am trying to add Tiles and keep having problems. If I right click on the project and "run As" -> "Run on Server" it will run as expected.

If I deploy the application as a WAR file to my local Tomcat instance it will deploy ok but when I try to access the application it fails with IllegalArgumentException in the tiles definition file.

I do have the Maven resources in the WEB-INF/lib directory. But there is still something that I must be missing when I export the war file. I've reviewed all the log files and can't see a difference. The server configured in Eclipse points to the same server I am running separately. It is Tomcat v7.0.70.

Here is the output from when I try to access the webpage:

Struts Problem Report

Struts has detected an unhandled exception:
Messages:   

    Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml
    Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml
Stacktraces
java.lang.IllegalArgumentException: Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml

    java.net.URI.create(Unknown Source)
    org.apache.struts2.tiles.StrutsWildcardServletApplicationContext.getResource(StrutsWildcardServletApplicationContext.java:105)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:232)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:203)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions(CachingLocaleUrlDefinitionDAO.java:192)
        org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitions(ResolvingLocaleUrlDefinitionDAO.java:68)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions(CachingLocaleUrlDefinitionDAO.java:174)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinitions(CachingLocaleUrlDefinitionDAO.java:131)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:105)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:49)
        org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition(UnresolvingLocaleDefinitionsFactory.java:89)
        org.apache.tiles.impl.BasicTilesContainer.getDefinition(BasicTilesContainer.java:286)
        org.apache.tiles.impl.BasicTilesContainer.isValidDefinition(BasicTilesContainer.java:273)
        org.apache.tiles.TilesContainerWrapper.isValidDefinition(TilesContainerWrapper.java:88)
        org.apache.tiles.impl.mgmt.CachingTilesContainer.isValidDefinition(CachingTilesContainer.java:100)
        org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:139)
        org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:208)
        com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:366)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:270)
        com.opensymphony.xwork2.interceptor.LoggingInterceptor.intercept(LoggingInterceptor.java:68)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
        com.opensymphony.xwork2.interceptor.TimerInterceptor.intercept(TimerInterceptor.java:121)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
        org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
        org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
        org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
        org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
        org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
        java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        java.lang.Thread.run(Unknown Source)


java.net.URISyntaxException: Illegal character in path at index 13: file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml

        java.net.URI$Parser.fail(Unknown Source)
        java.net.URI$Parser.checkChars(Unknown Source)
        java.net.URI$Parser.parseHierarchical(Unknown Source)
        java.net.URI$Parser.parse(Unknown Source)
        java.net.URI.<init>(Unknown Source)
        java.net.URI.create(Unknown Source)
        org.apache.struts2.tiles.StrutsWildcardServletApplicationContext.getResource(StrutsWildcardServletApplicationContext.java:105)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:232)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadRawDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:225)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitionsFromResources(CachingLocaleUrlDefinitionDAO.java:203)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.loadDefinitions(CachingLocaleUrlDefinitionDAO.java:192)
        org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO.loadDefinitions(ResolvingLocaleUrlDefinitionDAO.java:68)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.checkAndloadDefinitions(CachingLocaleUrlDefinitionDAO.java:174)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinitions(CachingLocaleUrlDefinitionDAO.java:131)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:105)
        org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO.getDefinition(CachingLocaleUrlDefinitionDAO.java:49)
        org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition(UnresolvingLocaleDefinitionsFactory.java:89)
        org.apache.tiles.impl.BasicTilesContainer.getDefinition(BasicTilesContainer.java:286)
        org.apache.tiles.impl.BasicTilesContainer.isValidDefinition(BasicTilesContainer.java:273)
        org.apache.tiles.TilesContainerWrapper.isValidDefinition(TilesContainerWrapper.java:88)
        org.apache.tiles.impl.mgmt.CachingTilesContainer.isValidDefinition(CachingTilesContainer.java:100)
        org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:139)
        org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:208)
        com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:366)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:270)
        com.opensymphony.xwork2.interceptor.LoggingInterceptor.intercept(LoggingInterceptor.java:68)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
        com.opensymphony.xwork2.interceptor.TimerInterceptor.intercept(TimerInterceptor.java:121)
        com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:240)
        org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:54)
        org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:556)
        org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
        org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113)
        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
        org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
        org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
        java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
j   ava.lang.Thread.run(Unknown Source)


You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false

in your WEB-INF/classes/struts.properties file.
This is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<display-name>Team Info</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/config/SpringBeans.xml</param-value>
</context-param>
<context-param>
    <param-name>isLog4jAutoInitializationDisabled</param-name>
    <param-value>true</param-value>
</context-param>
    <context-param>
    <param-name>tilesDefinitions</param-name>
    <param-value>/WEB-INF/classes/tiles-def.xml</param-value>
    </context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
   <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>

        <interceptors>
            <interceptor name="authentication" class="com.teaminfo.interceptors.AuthenticationInterceptor" />
            <interceptor-stack name="authStack">
                <interceptor-ref name="timer" />
                <interceptor-ref name="logger" />
                <interceptor-ref name="authentication" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="authStack" />

        <default-action-ref name="dashboard" />

        <global-results>
            <result name="need_login" type="tiles">login</result>
            <result name="exception">/jsp/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="exception" />
        </global-exception-mappings>

        <action name="login" class="com.teaminfo.action.LoginAction">
            <interceptor-ref name="defaultStack" />
            <result name="success" type="redirectAction">dashboard</result>
            <result name="input" type="tiles">login</result>
        </action>
        <action name="dashboard" class="com.teaminfo.action.Dashboard">
            <result name="manager" type="tiles">manager</result>
            <result name="associate" type="tiles">associate</result>
        </action>
    </package>

</struts>
Tiles config
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
     "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
     "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>
    <definition name="mainTemplate" template="/jsp/layout.jsp">
            <put-attribute name="title"  value="Team Info" />
            <put-attribute name="header" value="/jsp/header.jsp" />
            <put-attribute name="menu" value="/jsp/menu.jsp" />
            <put-attribute name="body"   value="/jsp/body.jsp" />
            <put-attribute name="footer"   value="/jsp/footer.jsp" />
     </definition>

     <definition name="login" extends="mainTemplate">
        <put-attribute name="title" value="Team Info Login" />
        <put-attribute name="menu" value="/jsp/menu.jsp" />
        <put-attribute name="body" value="/jsp/login.jsp" />
     </definition>

     <definition name="admin" extends="mainTemplate">
        <put-attribute name="title" value="Team Info Admin" />
        <put-attribute name="menu" value="/jsp/admin/menu.jsp" />
        <put-attribute name="body" value="/jsp/admin/body.jsp" />
     </definition>

     <definition name="manager" extends="mainTemplate">
        <put-attribute name="title" value="Team Info Manager" />
        <put-attribute name="menu" value="/jsp/manager/menu.jsp" />
        <put-attribute name="body" value="/jsp/manager/body.jsp" />
     </definition>

     <definition name="associate" extends="mainTemplate">
        <put-attribute name="title" value="Team Info Manager" />
        <put-attribute name="menu" value="/jsp/associate/menu.jsp" />
        <put-attribute name="body" value="/jsp/associate/body.jsp" />
     </definition>

</tiles-definitions>

it doesn't like the space in the path. So the space should be changed with a %20 in this case. Use the replaceAll(" ","%20");

Otherwise, you can use encoding using URLEncoder.

String pathOfFile = "file:///C:/My Programs/apache-tomcat-7.0.70/webapps/TeamInfo/WEB-INF/classes/tiles-def.xml";
pathOfFile = URLEncoder.encode(pathOfFile, "UTF-8"); 
UPDATE1:

For tiles, you can replace your param value as below

    <param-value>
      /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
    </param-value>

instead of

<param-value>/WEB-INF/classes/tiles-def.xml</param-value>

For more, you can go through this tutorial.

test plan: Runnning a Web project on Tomcat., Open J2EE perspective, from the Dynamic Web Projects, right click and choose the web project, right click and select "Run As", you will see Apache Tomcat,  Standalone TOMCAT -> Not working . See the Eclipse Tomcat preferences, it might have added class path and library path which would make the Tomcat to identify. Faced similar problem in the past. Also, your static content works fine. It implies that some important jar to run is present in eclipse classpath which is not visible in Standalone Tomcat.

Apart from what ever SkyWalker has said, I would like to mention, deploying the war file which built in target folder of your project location's workspace to tomcat is also not the right way and will not most times wont work. You always need to right click on your project in eclipse -> export -> war and check Optimize for a specific server runtime and select Apache Tomcat. The exported war file, copy to your tomcat\webapps directory.

Hope it helps save time.

Dynamic Web Project, After setting up a dynamic web project, I get the following error: "Java compiler level does not match the version of the installed Java project facet" I am able to create this example and it runs on the tomcat 9 local server  The easiest way to test your new dynamic Web project and Tomcat server integration is to create a simple JSP and deploy it to Tomcat. You can create the new JSP file by selecting File > New > Other , or you can use the context-sensitive menu by right-clicking the project name in the Project Explorer view and selecting New > JSP .

Just in case this works for other people. You need to access your web application once deployed in tomcat with the very same name of your war.

Example.

If you exported your war as something.war then you must access your web app like http://localhost:8080/something

Can't get my web applications to deploy to Tomcat, My webapps are not deploying to Tomcat. At first folder in the running Tomcat server, there is no evidence that the webapp was ever deployed. to a dynamic web project, the project was automatically deployed to Tomcat's  When I right-click the project and choose “Run” or “Debug”, there is an option for running it as an application, but none for running on a server. I am guessing that eclipse only provides that option for “Dynamic Web Applications”, but this isn’t marked that way, and that’s just a guess.

How to run JSP in Eclipse IDE using Apache Tomcat Server, In this tutorial, we will create a simple JSP file and run it on Eclipse IDE using If you do not see dynamic web project option in Eclipse then refer this tutorial:  It is important to note that eclipse will not publish the application to the server's webapps folder. It will deploy this web application to a temporary folder. Therefore, leaving the Tomcat installation unmodified. If we do not change the configuration, Eclipse will publish the applications to the workspace folder:

How to create and run Servlet in Eclipse IDE, In order to run Servlet in Eclipse IDE, you need to have Apache tomcat Server If you do not see dynamic web project option in Eclipse then refer this tutorial:  Tomcat is a very popular web server/servlet container that can host Java web applications which are made up of servlets, JSP pages (dynamic content), HTML pages, javascript, stylesheets, images… (static content). This article describes the most common ways about how to deploy a Java web application on Tomcat, include the followings:

How to test and deploy WARs with Tomcat and Eclipse, Every developer needs to know how to integrate Tomcat and Eclipse. Follow This video is Duration: 5:22 Posted: Dec 16, 2019 1. In Eclipse for Java EE go to Window -> Preferences in Windows OS (or Eclipse -> Preferences on Mac) 2. Go to Server and click Runtime Environments. 3. Click the “Add….” button. 4. In Apache tree select Tomcat 8 and check the checkbox “Create a new local server”. 5.

Comments
  • Error is probably due to the space between "My Programs" in the file path. stackoverflow.com/questions/4992317/…
  • I'm guessing the Eclipse Workspace isn't under "My Programs", so your web-app has no spaces in its path when deployed from there.
  • Actually Eclipse is installed in "Program Files (x86)" so the path has TWO spaces. I have to assume that Eclipse is hiding that fact.
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
  • I understand what you are saying. However, that is a constructed path. in web.xml it has "/WEB-INF/classes/tiles-def.xml". So I don't have a way to change it once the full file name is generated. We don't have admin authority here at the company I work for so I couldn't install it in "program files" so I created "My Programs" for Tomcat, MySQL and other software. I'm surprised it is just now encountering that as an issue. It's been working fine up until I added Tiles. I'll try renaming the directory