The file jboss-deployment-structure.xml can ne used to set application dependency against modules. The advantage of using this file (compared to the Manifest’s entry) is that you can define dependencies across top-level deployments and subdeployments.

An example of jboss-deployment-structure.xml

Here is an example which adds a deployed module to the application's classpath:

<jboss-deployment-structure>
  <deployment>
      <dependencies>
         <module name="deployment.itextpdf-5.4.3.jar" export="TRUE"/>
      </dependencies>
    </deployment>
</jboss-deployment-structure>

If we want a more restrictive policy, we can include the dependency just for the sub-module named myapp.war which is included in the EAR:

<jboss-deployment-structure>  
   <sub-deployment name="myapp.war">
    <dependencies>
      <module name="deployment.itextpdf-5.4.3.jar" />
    </dependencies>
  </sub-deployment>  
</jboss-deployment-structure>

The above examples are using deployment-based dependencies; you can however reference your modules installed in the modules folder as in the following example where we are referencing log4j libraries:

<jboss-deployment-structure>
  <deployment>
    <dependencies>
      <module name="org.apache.log4j" export="TRUE"/>
    </dependencies>
    </deployment>
</jboss-deployment-structure>

If you need to provide a fine-grained control over your dependencies, you can exclude/include some packages from your dependencies. Let’s take as an example the following application which is composed of these artifacts:

MyApp.ear
|
|-- MyWebApp.war
|
|-- lib/itextpdf-5.4.3.jar

As it is, you don't need configuring the jboss-deployment-structure.xml to use the itext classes, which are picked up from the lib folder.

However, what if you want to select which packages to use of included itext library? That can be done by defining the itext library as a module and include a filter in it, which excludes for example the com/itextpdf/awt/geom package:

<jboss-deployment-structure>  
   <sub-deployment name="MyWebApp.war">
    <dependencies>
      <module name="deployment.itextpdf-5.4.3.jar" />
    </dependencies>
  </sub-deployment>  
   <module name="deployment.itextpdf-5.4.3.jar" >
    <resources>
     <resource-root path="itextpdf-5.4.3.jar" >
         <filter>
         <exclude path="com/itextpdf/awt/geom" />
       </filter>
     </resource-root>
    </resources>
  </module>  
</jboss-deployment-structure>

How to prevent your modules from being loaded using jboss-deployment-structure.xml

Here's for example how to prevent your application to use dom4j libraries and use the XOM (http://www.xom.nu/) object module which we have installed as module name "org.xom":

<jboss-deployment-structure>
   <deployment>
      <exclusions>
         <module name="org.dom4j" />
      </exclusions>
      <dependencies>
         <module name="org.xom" />
      </dependencies>
   </deployment>
</jboss-deployment-structure>

As a footnote, please be aware that you can use the slot parameter in the module name in order to specify a dependency against a particular

release of a module. In the following example we want to replace the default (main) implementation of the com.mysql module with the one contained in the slot named 1.26.

Here’s the view of the com.mysql folder under your modules tree:

~/jboss/wildfly-14.0.0.Final/modules:$ tree com
com
└── mysql
    ├── 1.26
    │   ├── module.xml
    │   └── mysql-connector-java-5.1.26-bin.jar
    └── main
        ├── module.xml
        └── mysql-connector-java-5.1.31-bin.jar

This is the corresponding configuration needed to use the slot 1.26 for your JDBC Driver:

<jboss-deployment-structure>
   <deployment>
      <exclusions>
         <module name="com.mysql" />
      </exclusions>
      <dependencies>
         <module name="com.mysql" slot="1.26" /> // <1>
      </dependencies>
   </deployment>
</jboss-deployment-structure>

How to prevent a subsystem from being loaded

Another feature of the jboss-deployment-structure.xml file is the ability to prevent the classloader to use a subsystem included in the application server. In the following example, we are excluding the resteasy subsystem that is used for consuming REST Messages:

<jboss-deployment-structure>
   <deployment>
    <exclude-subsystems>
      <subsystem name="resteasy" />
    </exclude-subsystems>
   </deployment>
</jboss-deployment-structure>

Please note that if the exclude-subsystem is specified for the top-level archive, it will be inherited by sub deployments, unless the sub deployments specify their own (possibly empty) list.

0
0
0
s2smodern