JBoss.org Community Documentation

21.5. Determining the deployment structure programmatically

Using the DeclaredStructure approach is convenient if you have an unusual deployment structure and don't mind adding the META-INF/jboss-structure.xml file to your deployment. However, if you have many deployments and want to avoid adding this file each time, or you want to nest arbitrary deployments inside your custom structure then you are better off creating your own StructureDeployer implementation.

The easiest way to do this is by extending the AbstractStructureDeployer class which already implements the StructureDeployer interface:


public abstract class AbstractStructureDeployer implements StructureDeployer
{
   ...
}

This includes helper methods to see if a VirtualFile represents a file or a directory and whether it corresponds to a top-level deployment. It also has methods to recurse through all of the files within a deployment to find nested deployments and to create ContextInfo objects for each one found. The only method that you need to implement is the one defined by the StructureDeployer interface:


public interface StructureDeployer extends Ordered
{
   boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException;
}

If you recognise the structure of the deployment then you must create a ContextInfo object containing the details and add it to the StructureMetaData . If you extend AbstractStructureDeployer then you can use the createContext() and addClassPath() helper methods to help do this. You must then return true to prevent any other StructureDeployer from analysing the deployment again.

If you want to control when your StructureDeployer is called you can use the relativeOrder property. By default this is set to Integer.MAX_VALUE in AbstractStructureDeployer . Implementations with a lower value are called before those with a higher value. If two values are the same then the return values of each implementation's toString() method are compared. The relativeOrder values for the out-of-the-box StructureDeployer implementations are:

  • DeclaredStructure - 0

  • JARStructure - 10000

  • FileStructure - Integer.MAX_VALUE

This means that DeclaredStructure is always called first followed by JARStructure and finally FileStructure.