1

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

Martin Höller
  • 2,714
  • 26
  • 44
  • Here is a link to a [related question](http://stackoverflow.com/questions/8289813/best-practice-for-loading-3rd-party-jars-in-jboss-as7-standalone-deployment) that has already some answers. – Martin Höller Nov 04 '13 at 16:43

1 Answers1

2

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.

siom
  • 1,610
  • 1
  • 14
  • 21
  • I don't know what the first linked page means by "EE subsystem" but obviously a JAR in an EAR is not part of it, as I get a "java.lang.ClassNotFoundException: javax.faces.context.FacesContext" when I remove the jboss-deployment-structure.xml. – Martin Höller Oct 23 '13 at 15:10
  • Have you packaged the jar, which contains your JSF backing beans and your references to FacesContext, in a war (i.e. jar in war in ear)? Have you specified your jar as webmodule using the maven-ear-plugin (see http://maven.apache.org/plugins/maven-ear-plugin/howto.html)? – siom Oct 23 '13 at 19:48
  • No, the JAR is not in the WAR but in the EAR. If it would be in the WAR I couldn't reference it from within other WARs. The JAR is not specified as webmodule. But as I understood it, only the WAR should be specified as webmodule, not JARs. – Martin Höller Oct 24 '13 at 06:08
  • Ok. So it seems that JBoss loads your jar not in the web subsystem context and therefore the jsf dependency is not automatically added. Are you sure that you want to use the same jar for all wars? What if you have to update your jar and war1 but you don't have the time/budget to update also war2? The classloading mechanism allows you to deploy the jar twice in different versions for both wars. – siom Oct 24 '13 at 08:27
  • If I'd update the JAR I'd give it a new version. war1 and war2 could then depend on different versions. However, this is only a theoretical problem as I currently have only one WAR. But we are getting off-topic :) My original question was: is my way of providing JSF2 API JAR to my backingbean JAR a hack or standard? – Martin Höller Oct 24 '13 at 08:57