Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Of course, Cargo is not limited to testing - You can also use it to configure, package or remotely handle many containers.

Info
titleAnt tasks and Maven 3 plugin

Codehaus Cargo can be used using its Java API as it is shown here. In addition to a Java API, Codehaus Cargo also has Ant tasks and a Maven 3 plugin:

The following examples demonstrate how to configure Resin 3Tomcat 9.0.15 78 to start with a standalone local configuration in target/resin3xtomcat9x and deploy a WAR located in path/to/simple.war using the Java API. The default port is 8080.

Please note that the container.start() and container.stop() methods wait until the container is fully started and fully stopped before continuing. Thus, for any action you are executing after, you are assured the container is completely operational.

...

titleANT tasks and Maven2 plugin

...

.

...

Static deployment

Static deployment means that the Deployable is deployed before the container is started. Here's an example using the strongly typed Java API:

Code Block
languagejava
Deployable war = new WAR("path/to/simple.war");

LocalConfiguration configuration =
    new Resin3xStandaloneLocalConfigurationTomcat9xStandaloneLocalConfiguration("target/myresin3xtomcat9x");
configuration.addDeployable(war);

InstalledLocalContainer container =
    new Resin3xInstalledLocalContainerTomcat9xInstalledLocalContainer(configuration);
container.setHome("c:/apps/resintomcat-39.0.1878");

container.start();
// Here you are assured the container is started.

container.stop();
// Here you are assured the container is stopped.

...

Code Block
languagejava
Deployable war = new DefaultDeployableFactory().createDeployable(
    "resin3xtomcat9x", "path/to/simple.war", DeployableType.WAR);

ConfigurationFactory configurationFactory =
    new DefaultConfigurationFactory();
LocalConfiguration configuration =
    (LocalConfiguration) configurationFactory.createConfiguration(
        "resin3xtomcat9x", ContainerType.INSTALLED,
            ConfigurationType.STANDALONE, "target/tomcat9x");
configuration.addDeployable(war);

InstalledLocalContainer container =
    (InstalledLocalContainer) new DefaultContainerFactory().createContainer(
        "resin3xtomcat9x", ContainerType.INSTALLED, configuration);
container.setHome("c:/apps/resintomcat-39.0.1878");

container.start();
// Here you are assured the container is started.

container.stop();
// Here you are assured the container is stopped.

...

Code Block
languagejava
InstalledLocalContainer container = new Resin3xInstalledLocalContainerTomcat9xInstalledLocalContainer(
    new Resin3xStandaloneLocalConfigurationTomcat9StandaloneLocalConfiguration("target/myresin3xtomcat9x"));
container.setHome("c:/apps/resintomcat-39.0.1878");

container.start();

// Here you are assured the container is started.

Deployable war = new WAR("path/to/simple.war");
Deployer deployer = new ResinInstalledLocalDeployerTomcatCopyingInstalledLocalDeployer(container);
deployer.deploy(war);

// HereTo yoube aresure NOT surethat the WARdeployable hasis finisheddeployed, deploying.we Tocan beuse surea youDeployableMonitor
// need to use a DeployableMonitor to monitor the deployment. For example
// theThe following code deploys the WAR and waitwaits until
// it is available to
// serve requests (i.e., the URL should point to a resource inside your WAR): specified returns an HTTP
// code 2xx or 3xx and, in our example, the text connection-ok in the body)
deployer.deploy(war, new URLDeployableMonitor(
    new URL("http://serverlocalhost:port8080/somesimple/urljsp-status"), "connection-ok"));

container.stop();

// Here you are assured the container is stopped.

...