This page last changed on Mar 17, 2006 by vmassol.
Definition
Cargo provides Ant tasks to perform all the operations available from the Java API
Explanation
Before using the Ant API you need to register the Cargo Ant tasks into Ant. This is done in the following manner:
<taskdef resource="cargo.tasks">
<classpath>
<pathelement location="${cargo-core-uberjar-0.7.jar}"/>
<pathelement location="${cargo-ant-0.7.jar}"/>
</classpath>
</taskdef>
Examples
Orion 2.x
Here's a full example showing how to deploy a WAR, and expanded WAR and an EAR in an Orion 2.x container. Please note that the output and log attribute are optional. The property elements allow you to tune how the container is configured. Here we're telling it to start on port 8180 and to generate the maximum amount of logs in the container output file.
<taskdef resource="cargo.tasks">
<classpath>
<pathelement location="path/to/cargo.jar"/>
</classpath>
</taskdef>
<cargo containerId="orion2x" home="c:/apps/orion-2.0.3" output="target/output.log"
log="target/cargo.log" action="start">
<configuration>
<property name="cargo.servlet.port" value="8180"/>
<property name="cargo.logging" value="high"/>
<deployable type="war" file="path/to/my/simple.war"/>
<deployable type="war" file="path/to/my/expandedwar/simple"/>
<deployable type="ear" file="path/to/my/simple.ear"/>
</configuration>
</cargo>
Tomcat 5.x
This example gives a walk through of how to get a Cargo Ant build to work with Tomcat 5.x .
Prerequisites
- It is assumed that Tomcat 5.x is already installed
- The cargo-core-uberjar-0.7.jar and cargo-ant-0.7.jar JARs have been downloaded
- A mimimum knowledge of Ant is required
- User already has a war target that properly generates a working war file
Steps
Follow the following steps to configure your build.xml :
- Create a folder under your basedir called cargolib that will hold cargo-core-uberjar-0.7.jar and cargo-ant-0.7.jar
- Define a property for cargolib
<property name="cargolib.dir" value="${basedir}/cargolib"/>
- Define 2 new properties cargo-uberjar and cargo-antjar as shown below:
<property name="cargo-uberjar" value="${cargolib.dir}/cargo-core-uberjar-0.7.jar"/>
<property name="cargo-antjar" value="${cargolib.dir}/cargo-ant-0.7.jar"/>
- Add additional properties for defining the following:
Property |
Description |
tomcat.home |
Installation directory of tomcat5x |
tomcatlog.dir |
This is where our logs are going to be generated |
tomcatconfig.dir |
Cargo needs an empty config folder |
pathtowarfile |
The full path of the war file e.g c:/devtools/myapp/dist/myfile.war |
- Add the following code to your build.xml :
<taskdef resource="cargo.tasks">
<classpath>
<pathelement location="${cargo-uberjar}"/>
<pathelement location="${cargo-antjar}"/>
</classpath>
</taskdef>
<target name="cargostart" depends="war">
<delete dir="${tomcatconfig.dir}" />
<mkdir dir="${tomcatlog.dir}"/>
<mkdir dir="${tomcatconfig.dir}"/>
<echo message="Starting Cargo..."/>
<echo message="Using tomcat.home = ${tomcat.home} "/>
<echo message="Using war = ${mywarfile} "/>
<echo message="Jars used = ${cargo-uberjar} , ${cargo-antjar}"/>
<cargo containerId="tomcat5x" home="${tomcat.home}" output="${tomcatlog.dir}/output.log"
log="${tomcatlog.dir}/cargo.log" action="start">
<configuration home="${tomcatconfig.dir}">
<property name="cargo.servlet.port" value="8080"/>
<property name="cargo.logging" value="high"/>
<deployable type="war" file="${mywarfile}"/>
</configuration>
</cargo>
<input>Press the Return key to stop Tomcat...</input>
</target>
 | Stopping Tomcat
If the following is not specified in the target:
<input>Press the Return key to stop Tomcat...</input>
the build after executing the cargostart target will just end with a BUILD SUCCESSFUL message and you won't get access to your webapp.The line of code above tells Ant not to stop the build process until the user presses the Return key, thus allowing you to access your webapp on port 8080 e.g http://localhost:8080/mywebapp |
|