Manage JBoss AS with Cargo

Cargo is a framework that allows you to manipulate Java EE containers in a standard way. It ships with a sets of Api, ant tasks and maven plugins that can let you execute administration and deployment tasks.

 

Installing Cargo

 

Cargo sources are available at http://cargo.codehaus.org/Downloads

 

If you need binaries, we suggest you downloading the latest bundle at http://ci.repository.codehaus.org/org/codehaus/cargo/cargo-core-uberjar/

 

Besides the cargo-core-uberjar, you will need the following dependencies:

 

Ant 1.5.4 or later

Commond discovery 0.4 or later

Commons logging 1.1 or later

You will need also dom4j 1.4 or later if you are deploying Datasources

 

Using Cargo Api to manage JBoss AS 6

In the following example we will show how to start, deploy a web application, stop JBoss AS 6 using Cargo Api.

In order to run this example, you will need to place in your application classpath cargo-core-uberjar and all its dependencies.


package sample;

import org.codehaus.cargo.container.InstalledLocalContainer;
import org.codehaus.cargo.container.configuration.LocalConfiguration;
import org.codehaus.cargo.container.deployable.Deployable;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.container.jboss.JBoss6xInstalledLocalContainer;
import org.codehaus.cargo.container.jboss.JBoss6xStandaloneLocalConfiguration;


public class Deployer {

  public static void main(String[] args) {
 
   Deployable war = new WAR("C:/Test.war");

   LocalConfiguration configuration =
        new JBoss6xStandaloneLocalConfiguration("target/jboss6x");
   configuration.addDeployable(war);

   InstalledLocalContainer container = 

        new JBoss6xInstalledLocalContainer(configuration);
   container.setHome("C:/jboss-6.0.0.Final");

   container.start();

   System.out.println("Started jboss");


   container.stop();
 
   System.out.println("Stopped jboss");

  }

}

As you can see, the Api is pretty intuitive. The Deployable interface defines a file archive to be deployed in a container (WAR, JAR, EAR).

A Local configuration is created as instance of JBoss6xStandaloneLocalConfiguration (In the next step we will show how to create a Standalone Configuration which can be used for any application server)

Finally a JBoss6xInstalledLocalContainer is created, setting its home to the location where JBoss 6 is installed.

The purpose of this script is to deploy a web archive named Test.war, start and stop the application server.

 

Using Cargo’s untyped Api

The same result can be obtained by using a ConfigurationFactory which delivers custom configuration for every type of application server:


Deployable war = new DefaultDeployableFactory().createDeployable(

"jboss6x", "C:/Test.war", DeployableType.WAR);

 ConfigurationFactory configurationFactory =
        new DefaultConfigurationFactory();

LocalConfiguration configuration =

       (LocalConfiguration) configurationFactory.createConfiguration(
          "jboss6x", ContainerType.INSTALLED, ConfigurationType.STANDALONE);
              configuration.addDeployable(war);

 InstalledLocalContainer container =
      (InstalledLocalContainer) new DefaultContainerFactory().createContainer(
          "jboss6x", ContainerType.INSTALLED, configuration);

 

container.setHome("C:/jboss-6.0.0.Final");

 container.start();
 
 container.stop();

Besides Java API, Cargo has got also ANT tasks and Maven plugins for managing your application server and its artifacts.

For further reading : http://cargo.codehaus.org/Home

Found the article helpful? if so please follow us on Socials