Sunday, March 30, 2008

mvn + tomcat for hot deployment

Also, one very powerful feature of Maven that I am messing around with right now is filtering and profile "mashups". Lets say, I want LRD (local rapid development ;-) on my workstation using Tomcat. Usually I would use the Jetty plugin because it is the ultimate for Maven LRD, but the majority of the time and to match what is in production, developers use Tomcat at a minimum. Here is a quick tip for creating a shared distributable app using the aforementioned.

In a existing Maven app, create the following structure:

src
|-main
|-filters
|-tomcat.properties
|-resources
|-context.xml

In your pom.xml we have something like
:


tomcat

false






src/main/filters/tomcat.properties





${basedir}/src/main/resources

true
../${build.finalName}/META-INF

context.xml





in tomcat.properties

context.docBase=${basedir}/target/${project.build.finalName}
context.path=/${project.build.finalName}

and in context.xml



Once you have all of this in place (along with a good cargo config found in this post) you will be on your way to a enjoyable, easy development setup.

So now, all you have to do to hot deploy your maven app to a running instance of Tomcat is type the following: mvn install -Ptomcat
This will compile and deploy your changes quickly. You can also set your IDE to copy jsp/xhtml files over using a keyboard shortcut mapping (easy to do with Idea) so for UI changes you don't have to hot deploy every time.
This example just scratches the surface of what mixing profiles with filtering can do. You could have a filtering/profile mechanism for every possible scenario.

No comments: