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.8.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.8.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.
    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.
    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.
    Dependencies: org.javassist, org.apache.velocity export

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>.
    <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.
    <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.
    <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.
    <module name="org.javassist" export="true" />

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

<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.
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.

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.

© 2024 Red Hat, Inc.