Jboss-deployment-structure.xml: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 7: Line 7:
* [[WildFly Deployment Descriptors]]
* [[WildFly Deployment Descriptors]]
* [[WildFly Modules]]
* [[WildFly Modules]]
=TODO=
<font color=red>Deplete: https://home.feodorov.com:9443/wiki/Wiki.jsp?page=JbossDeploymentStructure.xml</font>


=Overview=
=Overview=
Line 12: Line 16:
<tt>jboss-deployment-structure.xml</tt> is a WildFly proprietary deployment descriptor that allows finely grained class loading control.  
<tt>jboss-deployment-structure.xml</tt> is a WildFly proprietary deployment descriptor that allows finely grained class loading control.  


It must be placed in the <tt>META-INF</tt> or the <tt>WEB-INF</tt> directory of the deployment.
It must be placed in the <tt>META-INF</tt> (or the <tt>WEB-INF</tt>, if the deployment is a WAR) directory of the deployment.


It can be used for the following:
It can be used for the following:
* To prevents [[WildFly Modules#Automatic_Dependencies|automatic dependencies]] from being added.
* To prevents [[WildFly Modules#Implicit_Dependencies|implicit dependencies]] from being added.
* To add module dependencies.
* To add module dependencies.
* To define additional modules. <font color=red>What for? How is that useful?</font>
* To define additional modules. <font color=red>What for? How is that useful?</font>
Line 29: Line 33:
         Override the global 'ear-subdeployments-isolated' setting.  
         Override the global 'ear-subdeployments-isolated' setting.  
   -->
   -->
   <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
   <ear-subdeployments-isolated>true</ear-subdeployments-isolated>


   <!--  
   <!--  
Line 43: Line 47:
       -->
       -->
     <exclude-subsystems>
     <exclude-subsystems>
         <subsystem name="resteasy" />
         <subsystem name="resteasy"/>
     </exclude-subsystems>
     </exclude-subsystems>


     <!--
     <!--
         The 'exclusion' element prevents the addition of the specified automatic dependencies.
         The 'exclusion' element prevents the addition of the specified implicit dependencies.
     -->
     -->
     <exclusions>
     <exclusions>
         <module name="org.javassist" />
         <module name="org.javassist"/>
    </exclusions>
    </exclusions>
     <!-- This allows you to define additional dependencies, it is the same as using the Dependencies: manifest attribute -->
 
    <!-- Note that the export="true" is necessary if these dependencies are to be seen by the sub-deployments -->
     <!--  
    <!-- if export is not set or is set to false, then the dependencies are only visible to the classes in the jars in the ear lib -->
          This is how additional dependencies are defined (also 'Dependencies:' manifest attribute
          can be used. export="true" must be specified if the dependencies should be seen by the
          sub deployments. The default value is "false", and in this case, the dependencies are only  
          visible to the classes in the jars in the EAR's lib  
    -->
     <dependencies>
     <dependencies>
      <module name="deployment.javassist.proxy" export="true" />
        <module name="deployment.javassist.proxy" export="true"/>
      <module name="deployment.myjavassist" export="true" />
        <module name="deployment.myjavassist" export="true"/>
      <!-- Import META-INF/services for ServiceLoader impls as well -->
        <!--  
      <module name="myservicemodule" services="import"/>
              Import META-INF/services for ServiceLoader implementations
        -->
        <module name="myservicemodule" services="import"/>
     </dependencies>
     </dependencies>
     <!-- These add additional classes to the module. In this case it is the same as including the jar in the EAR's lib directory -->
 
     <!--  
          Use this element to add additional classes to the module. For EARs is similar to including the
          JAR to the EAR's lib directory.
    -->
     <resources>
     <resources>
      <resource-root path="my-library.jar" />
        <resource-root path="my-library.jar" />
    </resources>
        </resources>
   </deployment>
   </deployment>
  <!--
        The 'sub-deployment' element corresponds to the module for a WAR deployment and it can
        use the same tags as the main 'deployment' element.
  -->
   <sub-deployment name="myapp.war">
   <sub-deployment name="myapp.war">
    <!-- This corresponds to the module for a web deployment -->
    ...
    <!-- it can use all the same tags as the <deployment> entry above -->
     <dependencies>
     <dependencies>
      <!-- Adds a dependency on a ejb jar. This could also be done with a Class-Path entry -->
        <!--  
      <module name="deployment.myear.ear.myejbjar.jar" />
              Can be used to add a dependency on a sibling EJB jar, while there are no implicit dependencies
              on all others. This could also be done with a Class-Path entry.
        -->
        <module name="deployment.myear.ear.myejbjar.jar" />
     </dependencies>
     </dependencies>
     <!-- Set's local resources to have the lowest priority -->
 
    <!-- If the same class is both in the sub deployment and in another sub deployment that -->
     <!--  
    <!-- is visible to the war, then the Class from the other deployment will be loaded,  -->
          Specifies that a local resources to have the lowest priority: if the same class is both in the  
    <!-- rather than the class actually packaged in the war. -->
          sub-deployment and in another sub-deployment that is visible to the WAR, then the class
    <!-- This can be used to resolve ClassCastExceptions  if the same class is in multiple sub deployments-->
          from the other deployment will be loaded,  rather than the class actually packaged in the  
    <local-last value="true" />
          WAR. This can be used to resolve ClassCastExceptions  if the same class is in multiple  
          sub-deployments
    -->
    <local-last value="true" />
   </sub-deployment>
   </sub-deployment>
   <!-- Now we are going to define two additional modules -->
 
   <!-- This one is a different version of javassist that we have packaged -->
   <!--  
        The element can be used to define additional modules.
   -->
   <module name="deployment.myjavassist" >
   <module name="deployment.myjavassist" >
    <resources>
      <resources>
    <resource-root path="javassist.jar" >
          <resource-root path="javassist.jar" >
      <!-- We want to use the servers version of javassist.util.proxy.* so we filter it out-->
   
      <filter>
          <!--  
        <exclude path="javassist/util/proxy" />
                  We want to use the servers version of javassist.util.proxy.* so we filter it out
      </filter>
          -->
    </resource-root>
          <filter>
    </resources>
                <exclude path="javassist/util/proxy" />
          </filter>
        </resource-root>
    </resources>
   </module>
   </module>
   <!-- This is a module that re-exports the containers version of javassist.util.proxy -->
 
  <!-- This means that there is only one version of the Proxy classes defined         -->
   <!--  
          This is a module that re-exports the containers version of javassist.util.proxy. This means that  
          there is only one version of the Proxy classes defined.
  -->
   <module name="deployment.javassist.proxy" >
   <module name="deployment.javassist.proxy" >
     <dependencies>
     <dependencies>
Line 106: Line 138:
</jboss-deployment-structure>
</jboss-deployment-structure>
</pre>
</pre>
=Declaring a Dependency on another Module=
<pre>
<jboss-deployment-structure ...>
  <deployment>
    <dependencies>
        <module name="io.novaordis.playground.wildfly.custommodule" slot="1.0"/>
    </dependencies>
  </deployment>
</jboss-deployment-structure>
</pre>
More details: {{External|How to specify a dependency on a JBoss Module in JBoss EAP 6 / 7 https://access.redhat.com/solutions/341703}}
Note that the dependency on a module can also be declared in the MANIFEST.MF of the JAR that needs the module. For more details, see [[WildFly_Modules#Explicit_Dependencies|WildFly Modules - Explicit Dependencies]]
=Accessing JDK Classes=
Not all JDK classes are exposed to a deployment by default. They can be exposed to the deployment via the <tt><dependencies></tt> mechanism.
For classes like "javax.security.auth.spi.LoginModule", this works:
<pre>
<jboss-deployment-structure>
      <deployment>
        <dependencies>
            <module name="javax.api"/>
        </dependencies>
      </deployment>
</jboss-deployment-structure>
</pre>
For other JDK-included classes, this may also work:
<pre>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system export="true">
                <paths>
                    <path name="com/sun/corba/se/spi/legacy/connection"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>
</pre>
=Elements=
==<deployment>==
===<dependencies>===
====<module>====
<span id='deployment_dependencies_module_name'></span>'''name'''
<span id='deployment_dependencies_module_slot'></span>'''slot'''
<span id='deployment_dependencies_module_services'></span>'''services'''="none|import|export" - specifies whether and how services found in this dependency are used (default is "none"). Specifying a value of "import" for this attribute is equivalent to adding a filter at the end of the import filter list which includes the META-INF/services path from the dependency module. Setting a value of "export" for this attribute is equivalent to the same action on the export filter list.

Latest revision as of 17:49, 4 May 2017

External

Internal

TODO

Deplete: https://home.feodorov.com:9443/wiki/Wiki.jsp?page=JbossDeploymentStructure.xml

Overview

jboss-deployment-structure.xml is a WildFly proprietary deployment descriptor that allows finely grained class loading control.

It must be placed in the META-INF (or the WEB-INF, if the deployment is a WAR) directory of the deployment.

It can be used for the following:

  • To prevents implicit dependencies from being added.
  • To add module dependencies.
  • To define additional modules. What for? How is that useful?
  • To change an EAR deployments isolated class loading behavior, independently of the general setting described here: ear-subdeployments-isolated setting.
  • To add additional resource roots to a module.

Example

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">

  <!-- 
         Override the global 'ear-subdeployments-isolated' setting. 
  -->
  <ear-subdeployments-isolated>true</ear-subdeployments-isolated>

  <!-- 
         This configuration element corresponds to the top level deployment. For a WAR this is 
         the WAR's unique module, for an EAR is the top level module, which contains the classes
         in the EAR's lib folder.
   -->
  <deployment>

     <!-- 
         'exclude-subsystem' prevents a subsystems deployment unit processors running on 
          a deployment. This is equivalent with removing the subsystem only for this deployment.
      -->
     <exclude-subsystems>
         <subsystem name="resteasy"/>
     </exclude-subsystems>

     <!--
         The 'exclusion' element prevents the addition of the specified implicit dependencies.
     -->
     <exclusions>
        <module name="org.javassist"/>
     </exclusions>

    <!-- 
           This is how additional dependencies are defined (also 'Dependencies:' manifest attribute
           can be used. export="true" must be specified if the dependencies should be seen by the
           sub deployments. The default value is "false", and in this case, the dependencies are only 
           visible to the classes in the jars in the EAR's lib 
     -->
    <dependencies>
        <module name="deployment.javassist.proxy" export="true"/>
        <module name="deployment.myjavassist" export="true"/>
        <!-- 
               Import META-INF/services for ServiceLoader implementations
         -->
        <module name="myservicemodule" services="import"/>
    </dependencies>

    <!-- 
          Use this element to add additional classes to the module. For EARs is similar to including the
          JAR to the EAR's lib directory.
    -->
    <resources>
        <resource-root path="my-library.jar" />
        </resources>
  </deployment>

  <!-- 
        The 'sub-deployment' element corresponds to the module for a WAR deployment and it can
        use the same tags as the main 'deployment' element.
  -->
  <sub-deployment name="myapp.war">
     ...
    <dependencies>
        <!-- 
              Can be used to add a dependency on a sibling EJB jar, while there are no implicit dependencies
              on all others. This could also be done with a Class-Path entry.
         -->
        <module name="deployment.myear.ear.myejbjar.jar" />
    </dependencies>

    <!-- 
          Specifies that a local resources to have the lowest priority: if the same class is both in the 
          sub-deployment and in another sub-deployment that is visible to the WAR, then the class 
          from the other deployment will be loaded,  rather than the class actually packaged in the 
          WAR. This can be used to resolve ClassCastExceptions  if the same class is in multiple 
          sub-deployments
     -->
     <local-last value="true" />
  </sub-deployment>

  <!-- 
         The element can be used to define additional modules.
  -->
  <module name="deployment.myjavassist" >
      <resources>
          <resource-root path="javassist.jar" >
     
           <!-- 
                  We want to use the servers version of javassist.util.proxy.* so we filter it out
           -->
           <filter>
                <exclude path="javassist/util/proxy" />
           </filter>
         </resource-root>
     </resources>
  </module>

  <!-- 
           This is a module that re-exports the containers version of javassist.util.proxy. This means that 
           there is only one version of the Proxy classes defined.
  -->
  <module name="deployment.javassist.proxy" >
    <dependencies>
      <module name="org.javassist" >
        <imports>
          <include path="javassist/util/proxy" />
          <exclude path="/**" />
        </imports>
      </module>
    </dependencies>
  </module>
</jboss-deployment-structure>

Declaring a Dependency on another Module

<jboss-deployment-structure ...>
  <deployment>
    <dependencies>
        <module name="io.novaordis.playground.wildfly.custommodule" slot="1.0"/>
    </dependencies>
  </deployment>
</jboss-deployment-structure>

More details:

How to specify a dependency on a JBoss Module in JBoss EAP 6 / 7 https://access.redhat.com/solutions/341703

Note that the dependency on a module can also be declared in the MANIFEST.MF of the JAR that needs the module. For more details, see WildFly Modules - Explicit Dependencies

Accessing JDK Classes

Not all JDK classes are exposed to a deployment by default. They can be exposed to the deployment via the <dependencies> mechanism.

For classes like "javax.security.auth.spi.LoginModule", this works:

<jboss-deployment-structure>
      <deployment>
         <dependencies>
            <module name="javax.api"/>
         </dependencies>
      </deployment>
</jboss-deployment-structure>

For other JDK-included classes, this may also work:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
        <dependencies>
            <system export="true">
                <paths>
                    <path name="com/sun/corba/se/spi/legacy/connection"/>
                </paths>
            </system>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Elements

<deployment>

<dependencies>

<module>

name

slot

services="none|import|export" - specifies whether and how services found in this dependency are used (default is "none"). Specifying a value of "import" for this attribute is equivalent to adding a filter at the end of the import filter list which includes the META-INF/services path from the dependency module. Setting a value of "export" for this attribute is equivalent to the same action on the export filter list.