Control the order of application deployment on JBoss EAP 8/7/6
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 8.x
- 7.x
- 6.x
Issue
-
On JBoss Enterprise Application Platform 6 it difficult to control the order in which applications, packed in different ear-files, are deployed when the server is started.
-
We have multiple ear archives that need to be deployed in strict order, and the deployment order need to be remembered after a restart. How could this be done ?
-
How to deploy the application from the
admin-consolewhen one application is dependent on other application? -
Can EAP6 handle multiple deployments simultaneously? Or would deployment requests be queued and executed serially?
-
A "war" file should be deployed after the two "ear" files.
-
We have around 13 services that we are deploying to JBoss. All of these services are WAR's. We need to define an order of startup for these services. Additionally, all of these services are dependent on a resource adapter starting first. Can this be done?
-
How to put the order of deployment on different file types ?
-
We have got an application (abc.ear) that depends on a third party resource adapter (XYZ.rar).
How to reliably configure class loading dependency from abc.ear to XYZ.rar ?
We have other EARs depending on "abc.ear". Those do already use "ejb-ref" in their deployment descriptors and deployment activation is deferred until "abc.ear" is ready.
Within "abc.ear!abc-ejb.jar" we have "resource-ref"s pointing to connection factories set up and served by "XYZ.rar", hence the module dependency for being able to use those classes. -
In one of our application (A ), It has dependency on another application (B). So B application must be deployed in the JBOSS container before application A. But sometime, the contextpath for Application B is not loaded before Application A. In this case, our jboss server fails.
-
Is it possible to control the order of the deploying the application on different JBoss nodes?
Node1 has the applications A and B. Node2 has the applications C and D. Application C depends on A and application D depends on B. -
Our client application consists of a total of five deployments. All application properties and configuration details are packaged within a separate Spring Boot Config WAR, which is deployed to the same JBoss server group. During JBoss startup, all deployments attempt to start in parallel. As a result, the application WAR files are sometimes initialized before the Config WAR is fully available, causing them to fail during startup because they cannot retrieve the required configuration properties, such as data source details and other application settings.
Resolution
- Services that have
@EJB,@Resourceorenv-entryconfigured in the components deployment descriptor, will start after the injected resources have been started. - When a defined deployment order is required and JBoss cannot determine dependencies via analyzing the metadata, a feature to Content from redhat.atlassian.net is not included.support inter deployment dependencies was added with JBoss EAP 6.1. The section Inter deployment dependencies using
jboss-all.xmlbelow explains in detail how to configure this approach. - Prior to JBoss EAP 6.1 there was the workaround to provide custom scripts for the deployment. This is explained below in the section Script deployment via CLI.
Note:
- If the order is needed to have visibility of classes in an application, that can be fixed by declaring a module dependency on the deployment's module whose classes are needed via the
jboss-deployment-structure.xmlor in theMANIFEST.MFas described in this article1 - For service dependencies such as EJBs see this article2
- If initialization order of an EAR's subdeployments/modules is required, see this article3.
Script deployment via CLI
-
Create CLI scripts that will (un)deploy the applications in sequential order when the server is started/stopped.
-
JBoss EAP CLI also supports the concept of batch mode which allows to group commands and operations and execute them together as an atomic unit, i.e., if at least one of the commands or operations fails, all the other successfully executed commands and operations in the batch are rolled back.
Note: Using this approach will require that the application(s) will be undeployed via CLI before server shutdown and deployed each time the server is started.
Inter deployment dependencies using jboss-all.xml
As an example, to deploy a framework.ear and an app.ear where the app.ear depends on the framework.ear and the framework.ear need to be deployed/started before app.ear is deployed, a jboss-all.xml can be added, such as:
-
app.ear/META-INF/jboss-all.xml:<jboss umlns="urn:jboss:1.0"> <jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0"> <dependency name="framework.ear" /> </jboss-deployment-dependencies> </jboss>
See attached jboss-all-dependency-demonstration.zip which shows the jboss-all.xml usage.
Note: The example above is for an EAR deployment. As mentioned this works for top level deployments. If the top level deployment is a WAR or a JAR, place the jboss-all.xml inside of them and declare a dependency on another top level deployment. The jboss-all.xml goes in WEB-INF/ if the top level deployment is a WAR else it goes in META-INF/ for all other deployment types.
Note: When redeploying the application which is a dependent of others without deploying the others in JBoss EAP 6.2 CP4 and prior versions may encounter this issue: Redeploying deployment that has a dependent throws IllegalStateException in JBoss EAP 6.2
Note: This jboss-deployment-dependencies configuration is also documented in the official Configuration Guide.
To define dependency on a RAR, add like below in the EAR :
Created application.ear!META-INF/jboss-all.xml, containing:
<?xml version="1.0" encoding="utf-8"?>
<jboss xmlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="connector.rar"/>
</jboss-deployment-dependencies>
</jboss>
Note: Controlling the order of deploying the application on different JBoss nodes is not possible, as the application(s) which are deployed on Node1 are not aware of the application(s) deployed on Node2.
References:
How to declare classloading dependencies between deployments in JBoss EAP 8/7/6
https://access.redhat.com/site/solutions/308003
2: How to declare service lifecycle dependencies (such as EJB) between deployments in JBoss EAP 8/7/6
https://access.redhat.com/site/solutions/308013
3: How to control the initialization order of an EAR's subdeployments / modules in JBoss Enterprise Application
https://access.redhat.com/site/solutions/524873
Root Cause
- JBoss EAP since version 6 runs most of its start-up tasks in parallel , and it also loads services and classes on demand.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.