If you find yourself in need of a generic management tool that facilitates installing, starting, and stopping a container, plus the ability to deploy artifacts like war and ear files, then you may want to take a look at Cargo.
Briefly, Cargo is an innovative open source project that aims to automate container management in a generic fashion, such that the same API used to deploy a war file to JBoss can also start and stop Jetty. Cargo also can download and install a container automatically; and you can utilize Cargo’s API in a few different fashions, ranging from Java code to Ant tasks to Maven goals.
For example, if you’d like to create a repeatable deployment process that avoids environmental assumptions (like that the instance of the application server is properly configured, etc), you can use Cargo to automatically download and install a pre-defined kosher version, say of JBoss. Once JBoss has been installed and is started, you can then deploy artifacts and begin testing.
Using Ant to accomplish this process is actually quite simple. All you need are two jar files (at a minimum). If you are using the latest version of Cargo (at the time of this posting) then the two files are: cargo-core-uberjar-0.9.jar and cargo-ant-0.9.jar.
With these two files in your classpath, you can then create an Ant target that initializes Cargo’s task like so:
<taskdef resource="cargo.tasks">
<classpath>
<pathelement location="${libdir}/${cargo-jar}" />
<pathelement location="${libdir}/${cargo-ant-jar}" />
</classpath>
</taskdef>
Then you can download and install a container, plus start it as follows:
<cargo containerId="jboss4x" action="start" wait="false" id="${jboss.refid}">
<zipurlinstaller installurl="${jboss.installer.url}" />
<configuration type="standalone" home="${jboss.tmp.dir}">
</configuration>
</cargo>
Note, you can deploy ear and war files between the two configuration tags. Also note, if JBoss is already installed, Cargo won’t attempt to reinstall.
Lastly, if you’d like to stop JBoss, then you can issue the following command:
<cargo containerId="jboss4x" action="stop" refid="${jboss.refid}" />
A refid is required to find a process as these steps are logically broken up. Also note that Cargo requires two different directories to properly install and configure JBoss– you can not use the same directory.
Cargo makes automated and reliable deployments a non event because this framework manages the container environment so you don’t have to. Give it a try and you’ll see a drastic increase in your ability to choreograph deployments quickly.
For more information on using Cargo for repeatable testing check out