Cargo is a thin wrapper that allows you to manipulate various type of application containers (Java EE and others) in a standard way. In this tutorial we will learn how to use it to deploy applications on WildFly from your pom file.
Cargo provides the following APIs and tools:
- A Java API to start/stop/configure any of the supported containers.
- A Java API to (remotely or locally) deploy modules into these containers, be it a server alone, a farm or a cluster.
- A Java API to parse/create/merge JEE modules.
Let’s see how to use it to deploy an application to WildFly. You will need for that a valid pom.xml which is able to build a JEE module, for example a web application.
In order to use Cargo we will include into the pom.xml file a reference to the Cargo Plugin and the containerId, which in our case is “wildfly12x”:
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.6.7</version> <!-- Configuration to use with the container (which will also configure the deployer) --> <configuration> <container> <containerId>wildfly12x</containerId> <type>remote</type> </container> <configuration> <type>runtime</type> <properties> <cargo.remote.username>admin1234</cargo.remote.username> <cargo.remote.password>Password1!</cargo.remote.password> </properties> </configuration> </configuration> </plugin>
In order to deploy your application, simply run the Maven goal:
mvn cargo:deploy
In order to undeploy your application, simply run the Maven goal:
mvn cargo:undeploy
In the above example, we have assumed that Cargo will run against a remote WildFly application server. It is also possible to let Cargo donwload a fresh version of WildFly and deploy the application on the top of it. And you can do that with just one line as follows:
mvn clean verify org.codehaus.cargo:cargo-maven2-plugin:run \ -Dcargo.maven.containerId=wildfly12x \ -Dcargo.maven.containerUrl=http://download.jboss.org/wildfly/12.0.0.Final/wildfly-12.0.0.Final.zip