Configuring JBoss AS 7 deployment order
- Published: 21 June 2012
You can configure JBoss AS deployment order inside an EAR with a simple trick, here we will show how to do it!
If you are using application.xml 6.0 schema you have an handy element named initialize-in-order which, if set to true, initializes the modules in the same order they are listed. For example here the webapp.war will be initialized as first module of the ear:
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"> <application-name>sampleapp</application-name> <initialize-in-order>true</initialize-in-order> <module> <web> <web-uri>webapp.war</web-uri> <context-root>test</context-root> </web> </module> <module> <ejb>core-ejb.jar</ejb> </module> </application>
What if you need configuring the deployment order between two applications, say two EAR files ? then you can use jboss-deployment-structure.xml. jboss-deployment-structure.xml is a JBoss specific deployment descriptor that can be used to control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments).
For example, let's say you have app1.ear and app2.ear. Here we configured the deployment structure of app2.ear to depend on app1.ear, so that the former will be deployed first:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <dependencies> <module name="deployment.app1.ear" /> </dependencies> </deployment> </jboss-deployment-structure>
Important! If you need to configure a dependency toward one or more EAR files, which are deployed separately, then you need to use jboss-all.xml file as follows:
<jboss umlns="urn:jboss:1.0"> <jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0"> <dependency name="application1.ear" /> <dependency name="application2.ear" /> </jboss-deployment-dependencies> </jboss>