3.2. Add an Explicit Module Dependency to a Deployment


This task shows how to add an explicit dependency to an application. Explicit module dependencies can be added to applications to add the classes of those modules to the class path of the application at deployment.
Some dependencies are automatically added to deployments by JBoss EAP 6. See Section 3.9.1, “Implicit Module Dependencies” for details.

Prerequisites

  1. You must already have a working software project that you want to add a module dependency to.
  2. You must know the name of the module being added as a dependency. See Section 3.9.2, “Included Modules” for the list of static modules included with JBoss EAP 6. If the module is another deployment then see Section 3.1.7, “Dynamic Module Naming” to determine the module name.
Dependencies can be configured using two different methods:
  1. Adding entries to the MANIFEST.MF file of the deployment.
  2. Adding entries to the jboss-deployment-structure.xml deployment descriptor.

Procedure 3.1. Add dependency configuration to MANIFEST.MF

Maven projects can be configured to create the required dependency entries in the MANIFEST.MF file. See Section 3.3, “Generate MANIFEST.MF entries using Maven”.
  1. Add MANIFEST.MF file

    If the project has no MANIFEST.MF file, create a file called MANIFEST.MF. For a web application (WAR) add this file to the META-INF directory. For an EJB archive (JAR) add it to the META-INF directory.
  2. Add dependencies entry

    Add a dependencies entry to the MANIFEST.MF file with a comma-separated list of dependency module names.
    Copy to Clipboard Toggle word wrap
    Dependencies: org.javassist, org.apache.velocity
  3. Optional: Make a dependency optional

    A dependency can be made optional by appending optional to the module name in the dependency entry.
    Copy to Clipboard Toggle word wrap
    Dependencies: org.javassist optional, org.apache.velocity
  4. Optional: Export a dependency

    A dependency can be exported by appending export to the module name in the dependency entry.
    Copy to Clipboard Toggle word wrap
    Dependencies: org.javassist, org.apache.velocity export
  5. Optional: Dependencies using annotations

    This flag is needed when the module dependency contains annotations which need to be processed during annotation scanning, such as when declaring EJB Interceptors. If this is not done, an EJB interceptor declared in a module cannot be used in a deployment. There are other situations involving annotation scanning when this is needed too.
    Using this flag requires that the module contain a Jandex index. Instructions for creating and using a Jandex index are included at the end of this topic.

Procedure 3.2. Add dependency configuration to jboss-deployment-structure.xml

  1. Add jboss-deployment-structure.xml

    If the application has no jboss-deployment-structure.xml file then create a new file called jboss-deployment-structure.xml and add it to the project. This file is an XML file with the root element of <jboss-deployment-structure>.
    Copy to Clipboard Toggle word wrap
    <jboss-deployment-structure> 
    
    </jboss-deployment-structure>
    For a web application (WAR) add this file to the WEB-INF directory. For an EJB archive (JAR) add it to the META-INF directory.
  2. Add dependencies section

    Create a <deployment> element within the document root and a <dependencies> element within that.
  3. Add module elements

    Within the dependencies node, add a module element for each module dependency. Set the name attribute to the name of the module.
    Copy to Clipboard Toggle word wrap
    <module name="org.javassist" />
  4. Optional: Make a dependency optional

    A dependency can be made optional by adding the optional attribute to the module entry with the value of true. The default value for this attribute is false.
    Copy to Clipboard Toggle word wrap
    <module name="org.javassist" optional="true" />
  5. Optional: Export a dependency

    A dependency can be exported by adding the export attribute to the module entry with the value of true. The default value for this attribute is false.
    Copy to Clipboard Toggle word wrap
    <module name="org.javassist" export="true" />

Example 3.3. jboss-deployment-structure.xml with two dependencies

Copy to Clipboard Toggle word wrap
<jboss-deployment-structure>

   <deployment>

      <dependencies>
         <module name="org.javassist" />
         <module name="org.apache.velocity" export="true" />
      </dependencies>

   </deployment>

</jboss-deployment-structure>
JBoss EAP 6 will add the classes from the specified modules to the class path of the application when it is deployed.
Creating a Jandex index

The annotations flag requires that the module contain a Jandex index. You can create a new "index JAR" to add to the module. Use the Jandex JAR to build the index, and then insert it into a new JAR file:

Procedure 3.3. 

  1. Create the index

    Copy to Clipboard Toggle word wrap
    java -jar EAP_HOME/modules/org/jboss/jandex/main/jandex-1.0.3.Final-redhat-1.jar $JAR_FILE
  2. Create a temporary working space

    Copy to Clipboard Toggle word wrap
    mkdir /tmp/META-INF
  3. Move the index file to the working directory

    Copy to Clipboard Toggle word wrap
    mv $JAR_FILE.ifx /tmp/META-INF/jandex.idx
    • Option 1: Include the index in a new JAR file
      Copy to Clipboard Toggle word wrap
      jar cf index.jar -C /tmp META-INF/jandex.idx
      Then place the JAR in the module directory and edit module.xml to add it to the resource roots.
    • Option 2: Add the index to an existing JAR
      Copy to Clipboard Toggle word wrap
      java -jar EAP_HOME/modules/org/jboss/jandex/main/jandex-1.0.3.Final-redhat-1.jar -m $JAR_FILE
  4. Tell the module import to utilize the annotation index

    Tell the module import to utilize the annotation index, so that annotation scanning can find the annotations.
    Choose one of the methods below based on your situation:
    • If you are adding a module dependency using MANIFEST.MF, add annotations after the module name.
      For example change:
      Copy to Clipboard Toggle word wrap
      Dependencies: test.module, other.module
      to
      Copy to Clipboard Toggle word wrap
      Dependencies: test.module annotations, other.module
    • If you are adding a module dependency using jboss-deployment-structure.xml add annotations="true" on the module dependency.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat, Inc.