JBoss.org Community Documentation

21.4. Declaring a custom deployment structure

JBoss Microcontainer provides two StructureDeployer implementations out-of-the-box to recognise the most common forms of deployments; standalone deployment descriptors and packaged/unpackaged JAR archives. In addition it also includes a third implementation called DeclaredStructure .

DeclaredStructure allows you to specify the structure of a deployment, including any nested deployments, using an XML file called jboss-structure.xml placed in the deployment's META-INF directory. The contents of this file are:


<structure>
    <context>
        <path name=""/>
        <metaDataPath>
            <path name="OTHER-DIR"/>
        </metaDataPath>
        <classpath>
            <path name=""/>
        </classpath>
    </context>
</structure>

This describes a top-level deployment and specifies that deployment descriptors can be found in the OTHER-DIR directory and classes in the root directory. If you want to describe nested deployments then you simply need to create additional <context> elements and specify their paths relative to the root deployment:


<structure>
    <context>
        <path name=""/>
        <metaDataPath>
            <path name="OTHER-DIR"/>
        </metaDataPath>
        <classpath>
            <path name=""/>
        </classpath>
    </context>
    <context>
        <path name="nestedDeployment1"/>
        <metaDataPath>
            <path name="descriptors/xml/"/>
        </metaDataPath>
        <classpath>
            <path name="classes"/>
            <path name="thirdParty/classes"/>
        </classpath>
    </context
    <context>
        <path name="utils/nestedDeployment2"/>
        <metaDataPath>
            <path name="META-INF"/>
            <path name="config/descs/"/>
        </metaDataPath>
        <classpath>
            <path name="lib"/>
        </classpath>
    </context
</structure>

Here we've added two nested deployments, one directly underneath the top-level deployment and another in a subdirectory called utils. The first nested deployment has deployment descriptors located in its descriptors/xml directory and classes in either the classes or thirdParty/classes directories. The second nested deployment has deployment descriptors in either the META-INF or config/descs directories and classes in the lib directory.

Note

In order to ensure that any JAR files that you add META-INF/jboss-structure.xml to are correctly recognised by DeclaredStructure instead of JARStructure the DeclaredStructure has a relativeOrder of 0 and the JARStructure a relativeOrder of 10000. This means that the DeclaredStructure class will be consulted first when determining the structure of a deployment.

If you use the DeclaredStructure approach then you must specify all nested deployments in the META-INF/jboss-structure.xml file. This is because no recursion takes place once the structure has been determined. If you want the ability to nest other kinds of deployments within your custom deployment structure then it may be easier to create your own StructureDeployer implementation. Doing so will allow you to call the addAllChildren() method to perform the recursion.