Gary
Gary

Reputation: 63

JBoss AS 7: Non-EJB dependency in another EAR

I've got an EAR with the following structure:

ear.ear    
  mywar.war
    lib
      jar1.jar
      jar2.jar
      jar3.jar

I've got multiple WARs in the deployments directory and I'd like them to have jar1.jar. jar2.jar and jar3.jar from ear.ear as dependencies.

Is this possible?

I've tried the following for jboss-deployment-structure.xml with no luck.

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="deployment.ear.ear.jar1.jar"/>
            <module name="deployment.ear.ear.jar2.jar"/>
            <module name="deployment.ear.ear.jar3.jar"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

<?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="deployment.ear.ear.lib.jar1.jar"/>
                <module name="deployment.ear.ear.lib.jar2.jar"/>
                <module name="deployment.ear.ear.lib.jar3.jar"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>

Is it possible to have non-ejb JAR dependencies in a separate EAR?

Upvotes: 4

Views: 1853

Answers (2)

shonky linux user
shonky linux user

Reputation: 6428

Jar files in an ear are a deployed as a single module. You can indicate a dependency on these using jboss-deployment-structure.xml by specifying a dependency on the ear itself. You will also need to include any ejbs separately and include export="TRUE".

For example:

<?xml version="1.0" encoding="UTF-8"? xmlns="urn:jboss:deployment-structure:1.2">
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <!-- our module depends on the libs within myear.ear -->
            <module name="deployment.myear.ear" export="TRUE"/>
            <!-- and these ejbs -->
            <module name="deployment.myear.ear.ejb1.jar" export="TRUE"/>
            <module name="deployment.myear.ear.ejb2.jar" export="TRUE"/>
            <module name="deployment.myear.ear.ejb3.jar" export="TRUE"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Upvotes: 2

lpiepiora
lpiepiora

Reputation: 13749

You should be able to place the dependencies in the /lib folder of your ear, and your wars should see them.

From the JBoss AS7 documentation:

Ear deployments are multi-module deployments. This means that not all classes inside an ear will necessarily have access to all other classes in the ear, unless explicit dependencies have been defined. By default the EAR/lib directory is a single module, and every WAR or EJB jar deployment is also a separate module. Sub deployments (wars and ejb-jars) always have a dependency on the parent module, which gives them access to classes in EAR/lib, however they do not always have an automatic dependency on each other

You can also read more about class loading in JBoss AS 7: https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7

Upvotes: 2

Related Questions