wesleyhales.com

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.

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.

Running Seam 2.0 on Tomcat(EJB3) using Maven and Cargo

12 October 2007

Java | cargo | maven | seam | tomcat |

In this article I review a simple Seam 2.0.0.CR2 app that deploys to Tomcat 6.0.13 with JBoss Embedded Beta2.

It's great to see Seam move to Maven because tracking and installing all those dependencies in a local repository was a pain in the ass! This project is moving fast, and if you wanted to keep up with the latest version, it was a lot of work. So now that my life is easier, I thought I would make the Seam+EJB+Tomcat user's life a little easier also.

The following is included in this sample app:

  • Trinidad 1.0.2
  • JBoss RichFaces
  • JAAS
  • Drools
  • JBPM
  • And everything else that seam and Embedded/EJB3 provides out of box.

All you need to have is Maven 2.0.x installed. The rest is cake. During the installation Cargo will download a zip file from the JBoss Maven repository. This is the Tomcat 6.0.13 distro with Embedded already installed and setup. Nothing else has been added to it.

Directions

  1. Checkout the project and getting started directions Here

*Note - I used a stub for the datasource in TOMCAT_HOME/lib/deploy. Don't forget that this deploy directory is supposed to be the same as JBoss AS deploy directory.

I used a few cool things in the maven pom setup:

  • It seems you can trick cargo into using the latest version of tomcat. The documentation says Tomcat5x is only supported for the container, but I didn't have any problems using 6.0.x with the Tomcat5x containerId
  • The cargo.container.url can be local, there is an example in the web/pom.xml (at the bottom)...So once you have this downloaded in you target dir, I would copy it somewhere outside of target and change the cargo.container.url to point to it. It will save time from downloading and bandwidth. It would be cool to add it as a dependency and then unzip from your local maven repo, but I haven't tried it yet.
  • Like I mentioned earlier, if you want to disable auto start of the Tomcat server you should disable this section of the cargo plugin in web/pom.xml
     
     <executions> 
     <execution> 
     <id>start</id> 
     <phase>install</phase> 
    
     <goals> 
     <goal>start</goal> 
     </goals> 
     </execution> 
    
     <execution> 
     <id>deploy-app</id> 
     <phase>install</phase> 
     <goals> 
    
     <goal>deployer-deploy</goal> 
     </goals> 
     </execution> 
     </executions> 
     
    
  • I have another version of this sample app that uses profiles to build either an EAR for JBoss or a WAR for Tomcat+Embedded. Michael Yuan recently touched on this subject about the EAR+Seam maven impl and did a great job breaking it down. I will try to post the sample app that lets you build a war for Tomcat or an EAR for JBoss all based on the maven profile i.e... mvn install -Ptomcat or mvn install -Pjboss This is the power of Maven2 and there is soo much more you can do with it.

btw, I haven't blogged since I've become an employee for JBoss, a division of Red Hat. I'm working on the JBoss Portal Team and I must say that the company is awesome, my team is awesome, and everyone I have met and talked to have been, you guessed it, AWESOME!