问题
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
回答1:
JBoss AS 7 automatically adds some modules to the classpath of your application/ear. You can find a complete list here. This list mentions javaee.api and com.sun.jsf-impl for the web subsystem, hence you don't need to add them with your jboss-deployment-structure.
But the jboss-deployment-structure file will be necessary if you do more advanced options, e.g. if you want to use a different JSF version than the one shipped with JBoss without replacing the module. You then may want to read this.
Thus, as far as I can see from your description, you don't need the jboss-deployment-structure. Just set the scope for your jsf maven dependencies to provided
.
来源:https://stackoverflow.com/questions/19542214/how-to-put-jsf-provided-by-jboss-as7-on-the-classpath-of-a-jar-module