Chapter 16. Example: Deploying an Application with Bundles (JBoss EAP 4, 5, and 6)

Bundles are a very clean and easy way to deploy updated applications to JBoss EAP 6 servers. The bundles system maintains multiple versions of a given package and can deploy any of those versions to a specified compatible group. This is a great workflow for application lifecycles, since a stable version can be deployed to production servers while a development version can be deployed to test machines.

16.1. Creating a New Application

The jbossas.js script in the cliRoot/rhq-remoting-cli-4.9.0.JON320GA/samples/modules directory defines a set of custom functions that quickly create a bundle version and definition and then deploy it to the given JBoss servers.
The jbossas.js script requires the util.js and bundles.js scripts for supporting functions. These are all loaded automatically from the cliRoot/rhq-remoting-cli-4.9.0.JON320GA/samples/modules directory.
The deploy-to-and-restart-JBAS.js script defines a function called createAppAndRestartJBAS that creates and then deploys a bundle. The function takes seven parameters:
  • The path to the bundle archive file.
  • A configuration object that contains any tokens or variables required for the bundle configuration. In this example, no properties are passed, so the value is null. Details about the configuration are in the comments in the bundles.js file and general configuration information is in Section 12.5.2, “Changing Simple Configuration Properties”.
  • The name of the compatible group to which to deploy the bundle.
  • A name of the bundle destination.
  • A description for the bundle destination.
  • The base directory to which to deploy the bundle and, optionally, a subdirectory to deploy the bundle to.
For example:
rhqadmin@localhost:7080$ var bundleZipFile = /export/bundles/ 
rhqadmin@localhost:7080$ var deploymentConfiguration = null
rhqadmin@localhost:7080$ var groupName = "JBoss EAP 6 Group"
rhqadmin@localhost:7080$ var destinationName = "My App - JBoss EAP 6 Destination"
rhqadmin@localhost:7080$ var destinationDescription = "For my application"
rhqadmin@localhost:7080$ var baseDirName = "Deploy Directory"
rhqadmin@localhost:7080$ var deployDir = "helloWorldApp"
rhqadmin@localhost:7080$ createAppAndRestartJBAS(bundleZipFile, deploymentConfiguration, groupName, destinationName, destinationDescription, baseDirName, deployDir)
There are a number of private functions defined in the deploy-to-and-restart-JBAS.js script which provide support to the createAppAndRestartJBAS function. Those are explained in the comments in the deploy-to-and-restart-JBAS.js file.
The baseDirName variable must have a value of Deploy Directory or Profile Directory. Those two locations are then identified based on the connection information for the specified JBoss EAP resource which is accessed by the script.
The createAppAndRestartJBAS function has three parts: finding the resource group, creating the bundle, and restarting the JBoss servers in the group.
The first part searches for the specific group by the given group name, and it must match only a single resource group. Otherwise, it returns an error.
function createAppAndRestartJBAS(bundleZipFile, deploymentConfiguration, groupName, destinationName, destinationDescription, baseDirName, deployDir) {
    var gcrit = new ResourceGroupCriteria;

    var groups = ResourceGroupManager.findResourceGroupsByCriteria(gcrit);
    if (groups.empty) {
        throw "Could not find a resource group called " + groupName;
    } else if (groups.size() > 1) {
        throw "There are more than 1 groups called " + groupName;

    var group = groups.get(0);
    var targetResourceType = group.resourceType;
Part of the search instruction is to fetch the resource type for the given compatible group. That resource type is then used to create the bundle destination, which is associated with a group.
The next part creates the bundle and restarts the server resources.
    var deployFn = function(restartFn) {
The first part of create a bundle deployment is uploading the bundle archive to create a bundle version in the JBoss ON configuration.
        var bundleVersion = createBundleVersion(bundleZipFile);
Next, it creates the destination, which is the definition of where the bundle is to be deployed (the base and deployment directories), associated with a compatible group and with the bundle version.
        var destination = BundleManager.createBundleDestination(, destinationName, destinationDescription, baseDirName, deployDir,;
Once the destination and the version are defined, then they can be saved and deployed to the target resource group.
        var deployment = deployBundle(destination,bundleVersion, deploymentConfiguration, "Web application", false);

        if (deployment.status != BundleDeploymentStatus.SUCCESS) {
            throw "Deployment wasn't successful: " + deployment;
When the deployment completes, then the script iterates through the group members (defined in one of the help functions in the deploy-to-and-restart-JBAS.js script) and restarts each resource. It then prints the deployment information.

        return deployment;
The deploy-to-and-restart-JBAS.js script can deploy content to any supported version of JBoss EAP: 4, 5, or 6. The bundle system uses the configuration defined in the resource plug-in, based on the resource type of the group. For the restart operation, different restart function are defined for each version of JBoss EAP.
    if (targetResourceType.plugin == "JBossAS" && == "JBossAS Server") {
        return deployFn(_restartAS4);
    } else if (targetResourceType.plugin == "JBossAS5" && == "JBossAS Server") {
        return deployFn(_restartAS5);
    } else if (targetResourceType.plugin == "JBossAS7" &&
            ( == "JBossAS7 Standalone Server" ||
           == "JBossAS-Managed")) {
        return deployFn(_restartAS7);

    throw "The resource group the destination targets doesn't seem to be a JBoss AS server group.";