Reputation: 1591
I'm trying to integrate Maven to my web project. I want t run project with mvn tomcat7:run, but when I do it maven creates new tomcat configuration in MyProject/target/tomcat and when I'm trying to open it on localhost and there is 404 error. Can anybody describe me what I should do to configurate maven to use local preconfigured tomcat instance?
Upvotes: 2
Views: 1237
Reputation: 43823
Maven creates a Tomcat configuration locally with mvn tomcat7:run
because you are running the webapp out of the /target
directory and the aim is to keep the running webapp isolated from any external configuration. For example if you required custom Tomcat configuration applying then Maven would need to modify the Tomcat conf beforehand. This might not be possible due to file system permission or could affect other webapps. So Maven copies the config locally, applies any custom configuration and starts Tomcat via the tomcat7-maven-plugin
.
One option is to look at the maven-cargo-plugin which can deploy a .war
built with Maven into an existing running Tomcat installation. With the correct configuration, instead or using mvn tomcat7:run
you would use mvn cargo:redeploy
to remove a running webapp and replace it with your freshly built webapp.
As an alternative Eclipse can be configured to start a Tomcat instance in which to run the webapp in. If you change the Eclipse project type to a Dynamic Web Project and then add a Tomcat instance to Eclipse by doing:
and point it do the Tomcat you downloaded. Eclipse will use this external Tomcat as a template to create an internal Tomcat configuration for your webapp. Lastly, the webapp needs to be configured to deploy the correct resources and libraries into Tomcat. By right clicking on the project root → Properties → Deployment Assembly, alter the list to match your resource locations. A standard set-up might look something like
/src/main/java | /WEB-INF/classes
/src/main/resources | /WEB-INF/classes
/src/main/webapp | /
Maven Dependencies | /WEB-INF/lib
Upvotes: 1