...
This tutorial demonstrates how to use the Cargo Maven 3 plugin to automatically start/stop a container (possibly deploying some deployables to it as it starts).
- Configuration
- Configuring an Embedded Jetty Container
- Setting the
JAVA_HOME
for the container - Automatic deployment of project's artifact (for J2EE for J2EE, Java EE or Jakarta EE projects)
- Automatically executing and stopping the container when running
mvn install
- Adding JARs to the container's classpath
- Adding JDBC DataSources to the container's JNDI tree
- Adding POJO or JavaMail Resources to the container's JNDI tree
Info | ||
---|---|---|
| ||
We have several Maven 3 Archetypes that contain sample Maven 3 projects with different use cases for the Codehaus Cargo Maven 3 plugin, we would really recommend that you check them out. For more details, read here: Maven 3 Archetypes. |
...
If you have a container that is already installed and configured, say with other deployables already in there, you may want to use an existing configuration. This done by specifying <type>existing</type>
. In that case you won't be able to control the configuration from Cargo (like port to use, logging levels, etc) as it'll be defined externally.
Tip | ||
---|---|---|
| ||
The CARGO Codehaus Cargo container definiton as well as the various application ping options in CARGO in Codehaus Cargo have a |
...
Anchor | ||||
---|---|---|---|---|
|
Setting the JAVA_HOME
You can set an alternate JAVA_HOME
for non-embedded containers. This will allow you to run a container that uses JDK 1.4 6 even if your build runs on Java 58. Here's an example of how to do this.
Code Block | ||||
---|---|---|---|---|
| ||||
[...] <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven3-plugin</artifactId> <configuration> [...] <properties> <cargo.java.home>/usr/package/j2dsk1.4.2_11<jdk-6u45-linux-x64</cargo.java.home> </properties> [...] </configuration> </plugin> [...] |
Anchor | ||||
---|---|---|---|---|
|
Automatic deployment of project's artifact (
...
for J2EE, Java EE or Jakarta EE projects)
If your project is a J2EE, Java EE or Jakarta EE project (i.e. of type <packaging>war</packaging>
, <packaging>ear</packaging>
, <packaging>ejb</packaging>
or <packaging>uberwar</packaging>
) and you use the Cargo m2 plugin on that project then the generated artifact will be automatically added to the list of deployables to deploy. You can control the location of the artifact by using the <location>
element (it defaults to ${project.build.directory}/${project.build.finalName}.${project.packaging
}). In addition if you want to wait for the deployment to be finished you can specify a <pingURL>
(none is used by default). Here's an example:
...
Automatically executing and stopping the container when running mvn install
You might to automate the execution of cargo:start
and cargo:stop
. Of course you can bind those goals to any lifecycle phase (see Maven's introduction to the lifecycle tutorial). Here's a common example used to start and the stop the container for doing integration tests:
...