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:

  1. [INFO]
  2. ————————————————————————
  4. [INFO]
  5. ————————————————————————
  6. [INFO] Failed to initialize ear modules
  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:

  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.

This entry was posted in Culture, Frameworks, Languages, Servers, Tips, Hacks, & Tricks, Tools and tagged , , , , , , , , , , , , . Bookmark the permalink.

7 Responses to "Maven: Including Axis2 Artifacts into EAR’s"

Leave a reply