The Maven JBoss plugin can be used to perform some common tasks like deploy/undeploy or add resources as part of your Maven goal. In the latest release of this plugin there is even the ability to perform the execution of Command Line Interface commands using it. This tutorial shows how to do all these things.
The Maven JBoss plugin, known as jboss-as-maven-plugin can be used to perform automatically some activities by connecting to a JBoss AS 7 running instance via the management port of the application server. If you don't provide any configuration detail about your server, the plugin will attemp connecting to the server located on localhost at port 9999.
So here's a minimal jboss-as-maven-plugin snippet which can be included into the plugin section of your Maven's pom.xml file:
With this file in place, you can deploy your Maven application by executing simply:
The application can be also redeployed using the
In order to undeploy issue the following command:
If your server is not running on the default address/port, you can use the following configuration parameters in order to connect to it:
The configuration stanza can be used also to specify domain deployment. In this case, we are deploying our application to the other-server-group:
By using the Maven JBoss plugin enables you also to start and stop the application server. In order to do that the jboss-as:start goal will start a JBoss Application Server. If the jboss-as.home property is not set, the server will be downloaded. The server will be shutdown when the maven process ends unless an explicit shutdown was invoked.
To execute the start goal type the following on the command line:
To execute the shutdown goal type the following on the command line:
How to deploy an application to multiple servers ?
Using the configuration parameters it's possible to parametrize the plugin and then publish the application to a different set of servers:
Then pass the host and port to the maven shell:
How to add JBoss AS 7 dependencies to your artifacts ?
As you probably know, with JBoss AS 7 you need to explicitily declare your dependencies (except for core libraries) using the Dependencies element in the MANIFEST.MF file. For example:
Dependencies: org.infinispan export
You can achieve the same thing using the Maven plugins adding some configuration parameters. For a Web application:
And for an EJB application: