Cargo : Starting and stopping a container This page last changed on Mar 18, 2006 by vmassol. Ability to start/stop a container (possibly deploying some deployables to it as it starts). In this scenario Maven 2 is used as a convenience to easily and quickly start a container. Example of a minimalist configuration:
    [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    [...]
Yes, you've read it right, there's no `<configuration>` element in this example! When you use this setup the Cargo m2 plugin will use a Jetty container by default. You can start the container with `mvn cargo:start` and stop it with `mvn cargo:stop`. Example of a lightweight configuration:
    [...]
    <configuration>

      <!-- Container configuration -->
      <container>
        <containerId>tomcat5x</containerId>
        <home>c:/apps/jakarta-tomcat-5.0.30</home>
      </container>

      <!-- Configuration to use with the container -->
      <configuration>
        <home>${project.build.directory}/tomcat5x</home>
      </configuration>

    </configuration>
    [...]
This minimal configuration allows you to configure a default Tomcat 5.x standalone configuration (when the configuration type is not defined as above, the plugin will use a standalone configuration by default) in `${basedir}/target/resin`. Example of a full-fledged m2 configuration:
    [...]
    <configuration>

      <!-- Container configuration -->
      <container>
        <containerId>orion2x</containerId>
        <home>c:/apps/orion-2.0.5</home> or
        <zipUrlInstaller>
          <url>http://www.orionserver.com/distributions/orion2.0.5.zip</url>
          <installDir>${java.io.tmpdir}/cargoinstalls</installDir>
        </zipUrlInstaller>
        <output>${project.build.directory}/orion2x/container.log</output>
        <append>false</append>
        <log>${project.build.directory}/orion2x/cargo.log</log>
      </container>

      <!-- Configuration to use with the container or the deployer -->
      <configuration>
        <type>standalone</type>
        <home>${project.build.directory}/orion2x</home>
        <properties>
          <cargo.servlet.port>8080</cargo.servlet.port>
          <cargo.logging>high</cargo.logging>
        </properties>

        <deployables>
          <deployable>
            <groupId>war group id</groupId>
            <artifactId>war artifact id</artifactId>
            <type>war</type>
            <properties>
              <context>optional root context</context>
            </properties>
          </deployable>
          <deployable>
            <groupId>ear group id</groupId>
            <artifactId>ear artifact id</artifactId>
            <type>ear</type>
          </deployable>
          [...]
        </deployables>

      </configuration>

    </configuration>
    [...]
This example shows the usage of a standalone configuration for configuring Orion 2.x. Note that it's possible to define deployables in the `<configuration>` element and they'll be deployed before the container starts (this is what we call static deployment). We have also defined some configuration properties to tell Cargo to configure Orion 2.x to start on port 8080 and to output highly verbose logs (useful for debugging). 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. ### Automatic deploymeny of project's artifact (for J2EE projects) If your project is a J2EE project (i.e. of type `<packaging>war</packaging>`, `<packaging>ear</packaging>`, etc) 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:
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <configuration>
        [...]
        <configuration>
          [...]
          <deployables>
            <deployable>
              <location>$\{project.build.directory\}/$\{project.build.finalName\}.$\{project.packaging\}</location>
              <pingURL>http://localhost:port/mycontext/index.html</pingURL>
            </deployable>
          </deployables>
          [...]

Document generated by Confluence on Mar 22, 2006 15:28