Overview: I have a JEE6 project that uses Apache Maven as the build system. My project produces an EAR that contains some common JARs, some EJB modules and a WAR. The produced EAR should be deployed to JBoss AS 7 (7.1.1 for now).
Best practices: If you have a web-application (like mine) and the classes for the webapp (managed beans) might be reused in other projects, it is the recommended way (the maven way) to package these classes into a separate JAR and make the WAR depend on this JAR. The JAR is then packaged with the EAR (but not inside the WAR). So far everything is working fine.
Here is the layout of my EAR:
EAR
+-- lib
| +-- [some 3rd party JARs]
| `-- war-backingbeans.jar
+-- myEJBs.jar
`-- myWAR.jar
Problem: The problem arises, when the classes in my backingbeans JAR start depending on some JSF classes like FacesContext
. JBoss AS7 comes with JSF JARs included and provides theses JARs for WARs on the classpath automatically. However, these JARs are not on the classpath of the EAR or other JARs in the EAR.
I could just add a corresponding dependency on the relevant JAR on the maven side, but that would end up with the JSF JARs packaged into the EAR. What I would actually like is JBoss to put it's JSF JARs on the classpath of the JAR.
I found a solution for this by providing a jboss-deployment-structure.xml
file in the META-INF
directory of the EAR with the following content:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="javax.faces.api" slot="main" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
My question is now, am I doing it the right way or is this considered a hack? Are there better/more portable solutions to my problem?
Many thanks in advance,
- martin