Dónal
Dónal

Reputation: 187529

deploy project to Tomcat from Eclipse

I'm trying to deploy a multi-module Maven project from Eclipse to a local Tomcat. The project has the following structure:

root [packaging: pom]
|
|--- domain [packaging: jar]
|
|--- manager [packaging: jar]
|
|--- web [packaging: war]

I import all the projects into Eclipse, then add the "Dynamic Web Module" facet to the web project

enter image description here

In the Runtimes tab of the same dialog, I configure the project to use a (local) Apache Tomcat v6.0 runtime.

I then right-click on the project and choose "Run As -> Run on Server" from the menu. In the following dialog I (again?) choose "Tomcat v6.0 Server"

enter image description here

In the following dialog, I add the web project to the list of configured projects

enter image description here

When I click "Finish", it appears from the console messages that the server has started, but when I go to http://localhost:8080/web/ in a browser I get a 404. I also tried http://localhost:8080/ and that also returns a 404, what am I doing wrong?

Upvotes: 6

Views: 33362

Answers (2)

Dónal
Dónal

Reputation: 187529

Success!!!

When I added the dynamic module Eclipse incorrectly created a WebContent directory. I deleted this directory and made the following change to the file in the .settings directory named org.eclipse.wst.common.component

<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<!--
<wb-resource deploy-path="/" source-path="/WebContent"/>
-->

Upvotes: 11

Vineet Reynolds
Vineet Reynolds

Reputation: 76709

I also tried http://localhost:8080/ and that also returns a 404.

I would infer that either Tomcat is not listening on port 8080, for the behavior is to display the contents of $CATALINA_HOME/webapps/ROOT/index.html as the welcome page. You might want to verify that Tomcat is configured to listen on port 8080 in the first place. The $CATALINA_HOME/conf/server.xml file should have entry similar to one listed below:

<Server port="8005" shutdown="SHUTDOWN">
    ...
    <Service name="Catalina">
        ...
        <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />

If you've got this right, but you are seeing a 404 response, then obviously something is wrong with the configuration. Either $CATALINA_HOME/webapps/ROOT does not exist, or something else which you might determine by looking at the logs in the $CATALINA_HOME/logs directory.

When I click "Finish", it appears from the console messages that the server has started, but when I go to http://localhost:8080/web/ in a browser I get a 404

Assuming that Tomcat has been configured successfully, this described behavior is likely if you do not have a welcome file listed in web.xml. The structure of the welcome-file-list is similar to the one listed below:

<web-app>
...
    <welcome-file-list>
        <welcome-file>somePage.html</welcome-file>
    </welcome-file-list>
...
</web-app>

Quite obviously, you'll need to have valid HTML in the welcome page. You could also have a JSP page to act as the welcome page.

Maven integration with Eclipse

I'm putting this in a separate section, as I'm unsure if your Eclipse project is setup correctly in the first place. Typically one would use either of m2eclipse or the maven-eclipse-plugin to configure a WTP project in Eclipse.

If you have added the Maven nature (using the m2eclipse plug-in) to the project, then you must know that m2eclipse has the tendency to revert any changes that might conflict the ones that it generates. For instance, m2eclipse would set the version Java facet to the source version specified for the maven-compiler-plugin in your pom.xml.

Also, it might be important to run the package phase, before deploying the application on the server. I've been tripped by this behavior on some occasions.

Upvotes: 0

Related Questions