此内容没有您所选择的语言版本。
3.2. Add an Explicit Module Dependency to a Deployment
Prerequisites
- You must already have a working software project that you want to add a module dependency to.
- 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.
- Adding entries to the
MANIFEST.MF
file of the deployment. - Adding entries to the
jboss-deployment-structure.xml
deployment descriptor.
Procedure 3.1. Add dependency configuration to MANIFEST.MF
MANIFEST.MF
file. See Section 3.3, “Generate MANIFEST.MF entries using Maven”.
Add
MANIFEST.MF
fileIf the project has noMANIFEST.MF
file, create a file calledMANIFEST.MF
. For a web application (WAR) add this file to theMETA-INF
directory. For an EJB archive (JAR) add it to theMETA-INF
directory.Add dependencies entry
Add a dependencies entry to theMANIFEST.MF
file with a comma-separated list of dependency module names.Dependencies: org.javassist, org.apache.velocity
Optional: Make a dependency optional
A dependency can be made optional by appendingoptional
to the module name in the dependency entry.Dependencies: org.javassist optional, org.apache.velocity
Optional: Export a dependency
A dependency can be exported by appendingexport
to the module name in the dependency entry.Dependencies: org.javassist, org.apache.velocity export
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
Add
jboss-deployment-structure.xml
If the application has nojboss-deployment-structure.xml
file then create a new file calledjboss-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 theWEB-INF
directory. For an EJB archive (JAR) add it to theMETA-INF
directory.Add dependencies section
Create a<deployment>
element within the document root and a<dependencies>
element within that.Add module elements
Within the dependencies node, add a module element for each module dependency. Set thename
attribute to the name of the module.<module name="org.javassist" />
Optional: Make a dependency optional
A dependency can be made optional by adding theoptional
attribute to the module entry with the value oftrue
. The default value for this attribute isfalse
.<module name="org.javassist" optional="true" />
Optional: Export a dependency
A dependency can be exported by adding theexport
attribute to the module entry with the value oftrue
. The default value for this attribute isfalse
.<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>
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.
Create the index
java -jar EAP_HOME/modules/org/jboss/jandex/main/jandex-1.0.3.Final-redhat-1.jar $JAR_FILE
Create a temporary working space
mkdir /tmp/META-INF
Move the index file to the working directory
mv $JAR_FILE.ifx /tmp/META-INF/jandex.idx
- Option 1: Include the index in a new JAR file
jar cf index.jar -C /tmp META-INF/jandex.idx
Then place the JAR in the module directory and editmodule.xml
to add it to the resource roots. - Option 2: Add the index to an existing JAR
java -jar EAP_HOME/modules/org/jboss/jandex/main/jandex-1.0.3.Final-redhat-1.jar -m $JAR_FILE
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:Dependencies: test.module, other.module
toDependencies: test.module annotations, other.module
- If you are adding a module dependency using
jboss-deployment-structure.xml
addannotations="true"
on the module dependency.