Maven 2 vs. Ant (revisited)
30 October 2007
Java | ant | lrd | maven |
Almost a year since I made this entry and I think Maven is great for open source and commercial apps. Sure, there may be a few things you want to do that don't fit into the "Maven way" but for the most part, it is a great build system. Also, any one that uses IntelliJ Idea will fall in love with Maven on first use (I guess it handles Eclipse project files just as well).
I recently worked on converting a JBoss Portal module from Ant to Maven and you can read about a few generic problems that I ran into and how to overcome them.
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
:
<profile>
<id>tomcat</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/filters/tomcat.properties</filter>
</filters>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<targetPath>../${build.finalName}/META-INF</targetPath>
<includes>
<include>context.xml</include>
</includes>
</resource>
</resources>
in tomcat.properties
context.docBase=${basedir}/target/${project.build.finalName}
context.path=/${project.build.finalName}
and in context.xml
<Context path="${context.path}" docBase="${context.docBase}" reloadable="true"/>
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.