Question

We have an application that until recently was a single Maven WAR project. We were using the Tomcat Maven plugin to run the application on local developer workstations using:

mvn tomcat:run

We were able to change JSP files while the embedded Tomcat instance was running and the changes would appear in web browsers just fine. I understand (from the plugin documentation) that when using the tomcat:run goal, the WAR is loaded as a dynamic web application and hence changes made to JSP files at source are picked up by Tomcat at runtime without restart.

The application has reached a fairly large size and we needed to reuse a large number of classes in a few different places besides the web project, so we refactored the code base into a multi-module Maven project. The structure is now:

parent Maven POM
    |
     ---- artifact1.jar
    |
     ---- artifact2.jar -> depends on artifact1.jar
    |
     ---- artifact3.jar -> depends on artifact1.jar
    |
     ---- artifact4.jar -> depends on artifact2.jar and artifact3.jar
    |
     ---- artifact5.war -> depends on artifact1.jar, artifact2.jar, artifact3.jar and artifact4.jar

After the refactoring we were unable to use tomcat:run from the project's root directory to run the WAR project as the plugin was unable to detect the JAR artifacts. So, we switched to using the tomcat:run-war-only plugin. The WAR module now launches fine.

However, from the documentation, it seems that the run-war-only goal treats WAR files as packaged web applications. Therefore, any changes we make to JSP files now are not picked up by the embedded Tomcat server while running. For every change to JSP files we have to restart the server.

Is there a way for us in this multi-module Maven set up to run WAR projects as dynamic web applications so that at least changes to JSP files are picked up by Tomcat without restarting?

Was it helpful?

Solution

Just do an mvn install first and then

mvn -pl artifact5 tomcat:run 

OTHER TIPS

First use new version of the tomcat plugin now located at Apache see http://tomcat.apache.org/maven-plugin-2.0/.

Then if you use maven3, you simply use tomcat6/tomcat7:run from the top. All classes from modules will be added to your webapp classloader (will save some ios as you don't need to install all jars first !) see http://tomcat.apache.org/maven-plugin-2.0/run-mojo-features.html

HTH!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top