Angry Bill

tech talk radio

Archive for the 'maven' Category


Maven would be cool if…

Posted by billburke on February 22, 2008

Maven would be cool if the plugins weren’t so god awful!  I mean, are these plugin developers idiots?  Do they even use their crap?  I just spent a good day trying to get the maven-ear-plugin to work only to give up and do an assembly, only to run into different problems there.  Beyond being totally unintuitive, these specific plugins have horrible horrible documentation.  Add to this fact that the assembly plugin doesn’t even check its syntax.  For example, I had <fileset> and didn’t know why the stupid plugin wasn’t creating the fileset in the jar.  Well, its because I didn’t capitalize the ‘S’  <fileSet>.  Of course no error message.  I had to ditch maven-ear-plugin because it didn’t correctly put transitive dependencies in the directory I wanted automatically.

I just can’t believe people haven’t cleaned up this shit.  Are people really using Maven?   I WANT to like Maven, I WANT to use Maven.  Its too bad its so freakin painful.

Posted in java, maven | 11 Comments »

JBoss Unit Testing with Maven

Posted by billburke on February 13, 2008

Recently, I had the need to do some JBoss integration testing in a Maven environment. I had to piece together how to do this and couldn’t find one reference point that just gave me all the maven XML I had to cut/paste. So, I thought I’d log it here for others to reference. First of all, in your src/test/resources directory you need a jndi.properties file:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099

This isn’t used by any of the maven plugins i’m going to show you, but you will need it in your test code if you want to connect at all with JBoss. Next, here’s the build fragment of what you need in your pom.xml

   <build>
      <finalName>jsr311-war</finalName>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jboss-maven-plugin</artifactId>
            <configuration>
               <jbossHome>/Users/billburke/jboss/jboss-4.2.2.GA</jbossHome>
            </configuration>
            <executions>
               <execution>
                  <id>jboss-deploy</id>
                  <phase>pre-integration-test</phase>
                  <goals>
                     <goal>deploy</goal>
                  </goals>
                  <configuration>
                     <fileName>${basedir}/target/jsr311-war.war</fileName>
                  </configuration>
               </execution>
               <execution>
                  <id>jboss-undeploy</id>
                  <phase>post-integration-test</phase>
                  <goals>
                     <goal>undeploy</goal>
                  </goals>
                  <configuration>
                     <fileName>${basedir}/target/jsr311-war.war</fileName>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
               <skip>true</skip>
            </configuration>
            <executions>
               <execution>
                  <id>surefire-it</id>
                  <phase>integration-test</phase>
                  <goals>
                     <goal>test</goal>
                  </goals>
                  <configuration>
                     <skip>false</skip>
                  </configuration>
               </execution>
            </executions>
         </plugin> ...
      </plugins>
   </build>

First things first, is to use the Mojo JBoss plugin. This allows you to deploy/undeploy to JBoss. You must configure it to point to the JBoss home directory. I have it hardcoded, but you should use an environment variable. There are two executions that are run. One deploys a file I have in my projects target directory, the other undeploys it. These must run in the pre-integration-test phase and post-integration-test phase.

The next blob of XML deals with the Surefire test framework. Surefire will try to run tests before you have packaged and deployed your target archive. This is because in Maven’s lifecycle, testing comes before packaging and Surefire is automatically bound to run tests in the “test” phase. We turn this off and instead tell Surefire to run during the “integration-test” phase after our archive has been packaged and deployed to JBoss.

The mojo plugin also allows you to start and stop jboss. I could not get this to work with JBoss 4.2.2. Since I prefer to run JBoss manually when integration testing anyways, I was too lazy to investigate further.

Posted in jboss, maven | 4 Comments »