We’ve discussed the Deployment to Glassfish 3.x in Part 3 of the series. In this article, we’ll do Maven deployment to JBoss AS 5.x and JBoss AS 6.x. For readers regardless if you are new to the series or had been following it, you don’t have to finish reading all the article parts before coming to this, all you have to do is to first complete or understand Part 1 and Part 2 of the series (you can skip Part 3) before carrying out the deployment steps for JBoss Application Server in this article.

This article deals with the deployment to both JBoss AS 5.x and JBoss AS 6.x in the same approach in the perspective of Maven, as we will be using the same Maven plugin in our EAR module for both JBoss AS 5.x and JBoss AS 6.x. I’ll outline to you the necessary preparation and little changes on the codes (only for the integration-test module) in what you have carried over from Part 2 to accommodate the deployment requirements.

Warning On Compatibility

The contents outlined in the article are NOT compatible with JBoss AS 7.x.


JBoss Application Server 5.x & 6.x Setup Brief

The setup is relatively straight forward. This is what we need to do:

  • In this setup, we’ll create a separate server instance/domain name call dummyserver-standard.
  • We’ll create a mysql-ds.xml file to describe the data source properties for the connection to the MySQL database, the DB which is used through out this demo. If you are using other DB, please create a different *-ds.xml file by referring to JBoss’s documentation on data source setup.
  • As for setting up the respective JMS connection factories and queue destination, we’ll deal with this setup separately for both JBoss AS 5.x and JBoss AS 6.x because JBoss AS 6.x uses HornetQ as their messaging module, which is different from JBoss AS 5.x.

Maven Repositories & Dependencies

Before touching the application servers, let’s get the initial things right, this includes the maven repository definition and the correct dependencies on the pom.xml files. Please edit the root pom.xml file, located at <path<DummyDemoJavaEE5/pom.xml and change it to the below contents:

Have you notice the increase of repository URLs? In fact, for plain vanilla deployment, we don’t need that much of external repositories to be included, but because we are running the jboss-as-client within the integration-test module, it notoriously relies on many other dependencies and that is why we have to put these repository URLs as part of the reliance for integration test. We’ll look into the integration test later.

Using & Configuring The JBoss-Maven-Plugin

In order to deploy the EAR to the either the JBoss 5.x or 6.x App Server, we need the JBoss-Maven-Plugin. You may go to the plugin’s website and make a detail study of it. Anyway, here’s how to have the plugin configured with a very comprehensive config options which could be used in most deployment scenario. We’ll define the plugin in the DummyDemo-ear’s pom.xml file.

Please edit/replace the <path>/DummyDemoJavaEE5/project/DummyDemo-ear/pom.xml to the below:

pom.xml Explained:
Looking at the edited pom.xml, I have defined a property at the top called jboss.directory, with the value that points to the absolute path of the JBoss App Server directory. Please change this value accordingly. Moving down to the plugin section, both the “deploy” and “undeploy” plugin goals will only be executed during the package phase (I want to make the EAR deployed to the application server just after packing everything to the EAR file) and the clean build cycle respectively.

As for the plugin configurations, there are many options to be configured, which you can find them at the plugin page. But as for now, the above is sufficient. However, do take note on a few options listed below:

jbossHomeThe value of <jbossHome> has to be of the absolute path of the directory that the JBoss Application Server resides. Here, we can directly assign the value from ${jboss.directory}.
serverNameThe name of the server instance/domain that this plugin should be referring. For this demo project, the value should be dummyserver-standard.
hostNameThe IP address of the hostname of the target application server.
portThe port number for the application server’s admin-console or jmx-console, which usually is defaulted to 8080.
fileNames -> fileNameThe absolute path of the EAR to be pickup for deployment.

JBoss: Creating The Server Domain/Instance

I prefer to do this manually without relying on automation from the JBoss-Maven-Plugin. We will use the “standard” server instance configuration from either JBoss AS 5.x or JBoss AS 6.x in this demo. So, just perform the following:

  1. Please create a new directory by the name of “dummyserver-standard” in the location
  2. Copy all the contents of <JBOSS_HOME>/server/standard and place it in the new “dummyserver-standard” directory that you have just created.

JBoss: Configuring the DB Data Source

Since we are using the MySQL DB for this demo, just create the mysql-ds.xml file with the below contents and put it into the <JBOSS_HOME>/server/dummyserver-standard/deploy/ directory.

Don’t forget the place the JDBC driver in the <JBOSS_HOME>/server/dummyserver-standard/lib/ directory.

JBoss: Configuring the JMS Queue and Connection Factory

We need to create both Queue Connection Factory and the Queue destination for the DummyDemoJavaEE5 application. To do this, just following the instructions below:

JBoss AS 5.x Specific

  1. Go to the directory <JBOSS_HOME>/server/dummyserver-standard/deploy/messaging/ and edit the file connection-factories.xml, keep the current default contents as it is, but insert the below within the <server> tag:

    Safe the changes.
  2. Now, edit the destionations-service.xml file in the <JBOSS_HOME>/server/dummyserver-standard/deploy/messaging/ directory. Keep the default contents as it is, but insert the below portion within the <server> tag:

This will do for now on JBoss 5.x.

** For more information, please visit: Quick Note: How To Setup JMS Queue/Topic & Connection Factory On JBoss 5.x

JBoss AS 6.x Specific

Beginning from JBoss AS 6.x, the JBoss team had adopted the HornetQ as the messaging engine for JBoss AS. Just follow the below to get the queue and connection factory up and running:

  1. Change the working directory to <JBOSS_HOME>/server/dummyserver-standard/deploy/
  2. Create a file call dummy-hornetq-jms.xml (any jms related configuration file must have the filename suffix of -hornetq-jms.xml) and have the xml contents as the below:

This is for the JBoss AS 6.x.

** For more information on setting up Queues, Topic and Connection Factories on JBoss AS 6.x, please visit: Quick Note: How To Setup JMS Queue/Topic & Connection Factory On JBoss 6.x

The Right Dependency For Integration Test

Before deployment and performing the integration test, I would just want to highlight to you that we will be using the jboss-as-client as the depending library for running the integration test. If you check on mvnrepository.com, the jboss-as-client as several versions. For JBoss AS 5.1.0, we’ll use jboss-as-client version 5.1.0.GA; for JBoss AS 6.1.0, we’ll use the version 6.1.0.Final for the jboss-as-client.

Please edit the pom.xml in <path>/DummyDemoJavaEE5/integration-test/ with the below contents:

JBoss AS 5.1.0 Specific:

JBoss AS 6.1.0 Specific:

A little changes in integration test codes:

Not forgetting the context environment properties in the integration test classes, we have to change the environment properties of the below files at the constructor. I have place the modified unit test files found in <path>/DummyDemoJavaEE/integration-test/src/test/com/developerscrappad/itest/ at the below:

Codes for com.developerscrappad.itest.BMPIntegrationTest.java

Codes for com.developerscrappad.itest.CMPIntegrationTest.java

Codes for com.developerscrappad.itest.MDBIntegrationTest

Making Things Happen Step-By-Step

We will begin the Step 1 by starting the server instance. This applies to both JBoss AS 5.x and JBoss AS 6.x. If you study the JBoss-Maven-Plugin’s functionality, it has capabilities to configure the server instance, but as I have mentioned earlier, it is better for us to create and configure the server instance manually instead of depending on the plugin. The plugin now is to use just for deployment and undeployment on the server. Just following through the below to deploy the EAR.

** Multiple terminal encouraged…

Step 1: Starting the Server Instance/Domain

The JBoss-Maven-Plugin allows you to start the server instace by executing “mvn jboss:start” within the DummyDemo-ear module. But, I will not excourage that as we can’t possibly see the output traces of the server log, so we’ll start the server instance/domain through the command prompt from <JBOSS_HOME> itself.

  1. Change the working directory to <JBOSS_HOME>/bin/.
  2. To start the server instance, execute “run -c dummyserver-standard“.
  3. Just wait for the server to be started and correct any startup configuration error if you encounter any.

Step 2: Deploying the EAR File to the JBoss Application Server

This is a very “sensitive” step and the failure rate is usually high. If anything goes wrong, I would highly suggest that you revisit all procedures mentioned above or back track Part 1 and Part 2 of the series. Anyway, to deploy the EAR file, follow the steps below:

Full Deployment Including Running The Integration Test

  1. Please change the working directory to <path>/DummyDemoJavaEE5/.
  2. Execute the “mvn install” command. This command will start the JBoss domain (if it is not started) and it will deploy the EAR to the application server, and then, it will run the integration tests within the integration-test module.
  3. Just wait for Maven to download the dependencies through the internet (may take a long time…). But if things broke down due to network failure or if you have difficult resolving dependencies, I’ll use the “-U” flag to perform this again, e.g. “mvn install -U
  4. If it deploys properly, you should be able to see the below in the terminal:
    [INFO] Reactor Summary:
    [INFO] DummyDemoJavaEE5 .............................. SUCCESS [0.090s]
    [INFO] project ....................................... SUCCESS [0.006s]
    [INFO] DummyDemo-api ................................. SUCCESS [0.023s]
    [INFO] DummyDemo-ejb ................................. SUCCESS [0.033s]
    [INFO] DummyDemo-web ................................. SUCCESS [0.035s]
    [INFO] DummyDemo-appclient ........................... SUCCESS [0.052s]
    [INFO] DummyDemo-ear ................................. SUCCESS [3.529s]
    [INFO] integration-test .............................. SUCCESS [0.018s]
    [INFO] ----------------------------------------------------------------
    [INFO] ----------------------------------------------------------------

    If you have successfully completed this step, CONGRATULATIONS, your EAR file had been deployed and tested!

For Development Deployment (Without Running The Integration Test)

During development, we don’t need to always run the integration test for every single deployment, to achieve this while at your development with the JBoss App Server running, just perform the following:

  1. Change the working directory to <path>/DummyDemoJavaEE5/project/.
  2. For first time deployment of the EAR, just execute the command “mvn package” or “mvn install“.

Step 3: How to Undeploy or Redeploy the EAR to JBoss AS

In the midst of development, there will always be time when we need to redeploy the application again and again. To do that, just execute this at the <path>/DummyDemoJavaEE5/project/ working directory:

Just use the command: “mvn clean“. Since the the “undeploy” plugin goal was tagged with “clean” build-phase (just check on <path>/DummyDemoJavaEE5/project/DummyDemo-ear/pom.xml), when ever you execute the “clean” build cycle, it will perform the undeployment.

** Please take note that this command will fail if there is nothing to be undeploy on the JBoss App Server.

To RE-DEPLOY (only when there is an existing deployment in the JBoss app server):
Execute “mvn clean install” or “mvn clean package” at the terminal.

Summary on Part 4

Deployment to JBoss AS 5.x and JBoss AS 6.x through the JBoss-Maven-Plugin is pretty straight forward. The only thing that might caused annoyance is the long download time of dependency libraries when using the jboss-as-client for integration test. Overall, just make sure you have the right repository URLs, the right pom.xml in the DummyDemo-ear module and the integration-test module, you should do fine.

To Be Continue…

From here, I’ll be working on the Maven deployment on JBoss AS 7.x or Weblogic, which ever one comes first. So, stay tune.

Proceed To Part 5:

Building and Deploying Java EE EAR with Maven to Java EE Application Server (Part 5) – Deployment To WebLogic 10.3.x & Weblogic 12.x

Related Articles:

  • Building and Deploying Java EE EAR with Maven to Java EE Application Server (Part 1) – Project Directory Structure & Module Generation Through archetype:generate
  • Building and Deploying Java EE EAR with Maven to Java EE Application Server (Part 2) – Where to put your source codes and pom.xml (EJB, MDB, Web & Enterprise Application Client)
  • Building and Deploying Java EE EAR with Maven to Java EE Application Server (Part 3) – Deployment To Glassfish 3.x
  • Building and Deploying Java EE EAR with Maven to Java EE Application Server (Part 5) – Deployment To Weblogic 10.3.x & Weblogic 12.x
  • Max Lam
    About the Author

    Born and currently resides in Malaysia, a seasoned Java developer whom had held positions as Senior Developer, Consultant and Technical Architect in various enterprise software development companies.

    Related Posts

    So far, we’ve covered Maven deployment of Java EE EAR to Glassfish 3.x, JBoss 5.x & 6.x. In this...

    Things have changed since the JBoss team officially adopted HornetQ as their messaging module on...

    This is just a short reference for the impatiens or people who are always forgetful (like me) when...