Skip to content


Maven: Including Axis2 Artifacts into EAR’s

I'm going to skip over a rant about how much Axis2 sucks in order to pass a tip on how to include Axis2 artifacts (AAR's, MAR's, etc) into an EAR file using the Maven plugin to package EAR files, maven-ear-plugin. It's a pretty obvious solution but if you're in a hurry like I've been to convert a project from a single WAR to one with several EJB's, a WAR, etc, there are a lot of new things to learn all at the same time (how classloading works with EAR's in JBoss, how to share the same Hibernate transactions between your web app and EJB's, etc), and this was one of those little things which wasn't immediately obvious. If you're seeing exceptions like these when trying to package an EAR in Maven:

CODE:
  1. [INFO]
  2. ------------------------------------------------------------------------
  3. [ERROR] BUILD ERROR
  4. [INFO]
  5. ------------------------------------------------------------------------
  6. [INFO] Failed to initialize ear modules
  7.  
  8. Embedded error: Unknown artifact type[mar]
  9. [INFO]
  10. ------------------------------------------------------------------------
  11. [DEBUG] Trace

... you've came to the right place. :)

There are many ways to setup your package structure under Maven2 to build EAR's, but essentially what I do is create a root level project which packages a given application into an EAR, and nothing more. Once you have the maven-ear-plugin setup for the most part, all that you need to do is to tell the Maven EAR Plugin to treat the various Axis2 pieces of shit packages like JAR's:

CODE:
  1. <plugin>
  2.                 <artifactid>maven-ear-plugin</artifactid>
  3.                 <configuration>
  4.                     <archive>
  5.                         <manifest>
  6.                             <addclasspath>true</addclasspath>
  7.                         </manifest>
  8.                     </archive>
  9.                     <artifacttypemappings>
  10.                         <artifacttypemapping type="mar" mapping="jar"/>
  11.                         <artifacttypemapping type="aar" mapping="jar"/>
  12.                     </artifacttypemappings>
  13.                 </configuration>
  14.             </plugin>

This is just one of many gotcha's I learned about while working on an aforementioned project. In fact it's really pretty hard to find any comprehensive documentation on getting EJB3, Spring, and Hibernate working together on JBoss with a typical Java web application, especially while using Maven. I have a sample project I used to work through some of the integration issues with this, and will hopefully be able to wrap it up and add it to Google Code in the next few weeks to provide an example of getting all of these technologies to play together.

Posted in A Day In The Life Of, Culture, Frameworks, Hibernate, JBoss, Java, Languages, Maven, Servers, Spring, Tips, Hacks, & Tricks, Tools. Tagged with , , , , , , , , , , , , .

5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. it is artifactTypeMappings and not artifacttypemappings
    it is artifactTypeMapping and not artifacttypemapping

    In case anybody will try to cut&paste this info from your site :-)

  2. @Zoltan

    Maybe it was because I was using an older version at the time or something.. *shrugs*.. I copied and pasted that example out of some working code.

    Anyhow, I've updated the post to reflect case sensitivity-- thanks!

  3. I am using maven 2.0.9 on Solaris, and the lowercase versions were ignored, took me a while to figure it out :-) , anyways thank you for your post it was really helpful.

  4. Oleg said

    have you tried doing the same with ant? if you could post the syntax for ant build.xml that would be greatly appreciated!

  5. @Oleg

    Sorry, I've only done it using Maven.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.