How to configure JBoss / WildFly deployment order
You can configure JBoss EAP / WildFly deployment order in some simple steps. This article will show you how to do it!
Configuring Deployment order within an EAR file
If you want to deploy applications within an EAR file with a precise order, then you can use the element named initialize-in-order (available in application.xml 6.0 schema). This element, 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>
On the other hand, here is another example if you are using the https://jakarta.ee namespace in application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_10.xsd"
version="10">
<initialize-in-order>true</initialize-in-order>
<module>
<web>
<web-uri>sample.war</web-uri>
<context-root>sample</context-root>
</web>
</module>
<module>
<ejb>hello.jar</ejb>
</module>
</application>
Configuring deployment order between multiple deployments
What if you need configuring the deployment order between two applications, say two EAR files ? then you can use jboss-deployment-structure.xml. This file is a WildFly specific deployment descriptor that you can use to control class loading in a fine grained manner. You should place it 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>
For more examples of jboss-deployment-structure.xml check this article: Examples of jboss-deployment-structure.xml
Configuring deployment with the CLI
Finally, it’s worth mentioning you can use JBoss / WildFly CLI to deploy applications using a strict order. Simply use the “deploy” command which will deploy the single applications. Then, wait to complete before moving to the next command.
Besides it, if you wrap the deployment within a batch command, you will have a guarantee that, should one deployment fail, there will be a rollback of deployed applications:
batch
deploy /tmp/app1.war
deploy /tmp/app2.war
run-batch
Recommended Articles
Solving EAR Deployment Dependencies in WildFly and JBoss AS 7
Learn how to manage deployment dependencies in WildFly and JBoss AS 7 using jboss-all.xml files and CLI batches. Get a step-by-step guide on resolving EAR file dependencies.
Configure Jenkins for Remote WildFly and JBoss EAP Deployment with Maven Plugin
Learn how to use the Maven plugin to deploy your application remotely to a WildFly or JBoss EAP server using Jenkins.
Manage Exploded Deployments in WildFly for Efficient Java Enterprise Applications
Learn how to configure and explode deployments in WildFly for efficient Java enterprise applications. Discover the benefits of exploded deployments and get step-by-step guides on configuring and exploding your WildFly deployment.
Deploy Applications to WildFly: Custom Deployment Directory Tutorial
Learn how to configure custom deployment directories for WildFly applications. #WildFly #JavaDeployment #CloudNative