title: How to put JSF provided by JBoss AS7 on the classpath of a JAR module?
body: <p><strong>Overview</strong>: I have a JEE6 project that uses <a href="http://maven.apache.org" rel="nofollow">Apache Maven</a> 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 <a href="https://www.jboss.org/jbossas/" rel="nofollow">JBoss AS 7</a> (7.1.1 for now).</p>
  
  <p><strong>Best practices</strong>: 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 <a href="https://maven.apache.org/plugins/maven-war-plugin/faq.html#attached" rel="nofollow">recommended</a> <a href="http://maven.40175.n5.nabble.com/war-dependency-not-being-picked-up-tt115028.html#a115029" rel="nofollow">way</a> (<em>the maven way</em>) to package these classes into a <strong>separate JAR</strong> 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.</p>
  
  <p>Here is the layout of my EAR:</p>
  
  <pre><code>EAR
   +-- lib
   |    +-- [some 3rd party JARs]
   |    `-- war-backingbeans.jar
   +-- myEJBs.jar
   `-- myWAR.jar
  </code></pre>
  
  <p><strong>Problem</strong>: The problem arises, when the classes in my backingbeans JAR start depending on some JSF classes like <code>FacesContext</code>. 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.</p>
  
  <p>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.</p>
  
  <p>I found a solution for this by providing a <a href="https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7#ClassLoadinginAS7-JBossDeploymentStructureFile" rel="nofollow"><code>jboss-deployment-structure.xml</code></a> file in the <code>META-INF</code> directory of the EAR with the following content:</p>
  
  <pre><code>&lt;jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"&gt;
    &lt;deployment&gt;
      &lt;dependencies&gt;
        &lt;module name="javax.faces.api" slot="main" export="true"/&gt;
      &lt;/dependencies&gt;
    &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>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?</p>
  
  <p>Many thanks in advance,<br/>
  - martin</p>