Search Mastertheboss

Our eBooks

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


If you need binaries, we suggest you downloading the latest bundle at


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");

   InstalledLocalContainer container = 

        new JBoss6xInstalledLocalContainer(configuration);


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

   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);

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




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

For further reading :

Related articles available on

JBoss MBeans POJO

JMX MBean services are the core building blocks of the JBoss Appl

How to a dump of JNDI tree with JMX console ?

#2 JBoss Howto. This is the recipe of the day

How to configure JBoss to bind to a different IP ?

If you want to change the jboss.bind.address property use the&nbs

How to shut down JBoss from remote ?

JBoss recipe of the day

How to create multiple instances of an Mbean?

  Supposing you need two instances of an MBean, let's say one fo

JBoss classloader issues

By default JBoss (prior to version 3.2) uses a flat class loading

© 2020 All Rights Reserved.

Please publish modules in offcanvas position.