How To Order JBoss AS Deployments By Defining Custom Dependencies

When using JBoss AS5 (or 6), sometimes there is the need to explicitly control the deployment order of parts in a complex application. This need arises, mostly, from the fact that standard packages are not aware of Microcontainer way of working, its beans, or simple artifact deployments such as a plain lib jar.

 

For instance imagine that a EAR depends on Microcontainer bean, it is impossible for Microcontainer to know that the bean must be deployed before the EAR, since there is no meta data in the EAR which could be used by the Microcontainer to "guess" such dependency, at least not a way that would not mean a very long startup process.

 

Custom Dependency Metadata

 

Good news, there is a custom metadata file one can use to overcome the dependency issue explained above, it's called jboss-dependency.xml, and as all meta data, it should be put in the META-INF directory of the artifact that depends on others.

 

Note, there is no schema available at this point, but probably the simplest usage is enough to make it work, let's try an example.

 

<dependency xmlns="urn:jboss:dependency:1.0">
     <item whenRequired="Real" dependentState="Installed">
          MyMicrocontainerBeanName
     </item>
</dependency>

 

 

Consider that this meta data was added to a WAR's META-INF directory, this would tell Microcontainer that before deploying the WAR, the bean named MyMicrocontainerBeanName must first be deployed.

 

The whenRequired and dependentState attributes values in the example should work for commons usages, but for more flexible deployments these may be used to define when the artifact deployment needs the dependency, and in which state does such dependency should be, in order for the dependency to be considered to be resolved. For further information about what are the deployment stages and states please refer to JBoss Microcontainer documentation.

Deployment Aliases

So there is a way to set custom dependencies, which define an explicit order of deployment, but what if the dependency is not a Microcontainer bean, what if it is a simple library jar, what name do we use in the dependency <item/> value? There is another meta data that can be packaged, which defines aliases in Microcontainer, a file named aliases.txt, here is an example for its content:

 

MyMicrocontainerAliasName

 

 

By packaging such aliases.txt file in a JAR's META-INF directory, the jar could then be referenced in other Microcontainer meta data as MyMicrocontainerAliasName, so to define a dependency to such jar a jboss-dependency.xml would be:

 

<dependency xmlns="urn:jboss:dependency:1.0">
     <item whenRequired="Real" dependentState="Installed">
          MyMicrocontainerAliasName
     </item>
</dependency>

 

 

 

Other Resources

JBoss AS Custom Meta Data