JBoss application server tutorials

  • Full Screen
  • Wide Screen
  • Narrow Screen
  • Increase font size
  • Default font size
  • Decrease font size

Maven JBoss AS 7 plugin tutorial

 

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:

<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.3.Final</version>
            </plugin>
            ...
        </plugins>
        ...
    </build>
...
</project>

With this file in place, you can deploy your Maven application by executing simply:

mvn jboss-as:deploy

The application can be also redeployed using the

mvn jboss-as:redeploy

In order to undeploy issue the following command:

mvn jboss-as:undeploy

If your server is not running on the default address/port, you can use the following configuration parameters in order to connect to it:

<plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.3.Final</version>
                    <configuration>
                      <hostname>192.168.1.1</hostname>
                      <port>9999</port>
                      <name>useradmin123</name>
                      <password>password123</password>
                </configuration>
</plugin>

The configuration stanza can be used also to specify domain deployment. In this case, we are deploying our application to the other-server-group:

<plugin>
. . . . .
                <configuration>
                      <domain>
                         <server-groups>
                             <server-group>other-server-group</server-group>
                        </server-groups>
                      </domain>
                </configuration>
</plugin>

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:

mvn jboss-as:start

To execute the shutdown goal type the following on the command line:

mvn jboss-as:shutdown

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:

<plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.3.Final</version>
                    <configuration>
                    <hostname>${hostname}</hostname>
                    <port>${port}</port>                    
                </configuration>
</plugin>

Then pass the host and port to the maven shell:

mvn jboss-as:deploy -Dhost=192.168.0.1 -Dport=9999
mvn jboss-as:deploy -Dhost=192.168.0.1 -Dport=10199

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:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <configuration>
      <archive>
         <manifestEntries>
            <Dependencies>org.infinispan export</Dependencies>
         </manifestEntries>
      </archive>
   </configuration>
</plugin>

And for an EJB application:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-ejb-plugin</artifactId>
   <version>${version.ejb.plugin}</version>
   <configuration>
      <ejbVersion>3.1</ejbVersion>
      <archive>
         <manifestEntries>
            <Dependencies>org.infinispan export</Dependencies>
         </manifestEntries>
      </archive>
   </configuration>
</plugin>



Francesco Google+
Top Programming Sites
You are here Projects Maven tutorials Maven and JBoss/WildFly Maven JBoss AS 7 plugin tutorial