Buy Support Online

Deploying to Payara Server Using the Maven Cargo Plugin

31 May 2018

When creating a Java EE application it is important to deploy and test it on a server that is as close to the target production environment as possible. If you use Maven in your project, it is possible to do so using the Cargo plugin, which allows you to deploy an application to an instance of Payara Server either locally or remotely. A complete example is available at https://github.com/payara/Payara-Examples/tree/master/payara-maven.

 

The cargo plugin can be added to a Maven project by adding the following to the <plugins> section of the pom:

 

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.6.7</version>
  <executions>
   ...
  </executions>
</plugin>

 

Execution Goals

There are four common goals you may use in your execution:

  • start
    runs goal start to start a local Payara server in background (not possible with remote deployment type)

  • redeploy
    runs goal redeploy to deploy the built application (will undeploy if needed)

  • undeploy
    runs goal undeploy to undeploy the built application

  • stop
    runs goal stop to stop the server running in background (not possible with remote deployment type)

An example of how you might use those goals to run an integration test:

 
<execution>
    <id>deploy</id>
    <phase>pre-integration-test</phase>
    <goals>
        <goal>start</goal
        <goal>redeploy</goal>
    </goals>
</execution>
<execution>
    <id>undeploy</id>
    <phase>post-integration-test</phase>
    <goals>
        <goal>undeploy</goal>
        <goal>stop</goal>
    </goals>
</execution>

 

Deploying to a Remote Instance of Payara Server

To deploy to a remote instance of Payara Server add the following configuration to the profile you are using:

 
<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <container>
      <containerId>glassfish5x</containerId>
      <type>remote</type>
    </container>
    <configuration>
      <type>runtime</type>
      <properties>
        <username>admin</payara.username>
        <password></payara.password>
        <hostname>localhost</payara.hostname>
        <cargo.remote.username>${username}</cargo.remote.username>
        <cargo.remote.password>${password}</cargo.remote.password>
        <cargo.glassfish.admin.port>4848</cargo.glassfish.admin.port>
        <cargo.hostname>${hostname}</cargo.hostname>
      </properties>
    </configuration>
  </configuration>
  <!-- provides JSR88 client API to deploy on Payara Server -->
  <dependencies>
    <dependency>
      <groupId>org.glassfish.main.deployment</groupId>
      <artifactId>deployment-client</artifactId>
      <version>5.0</version>
    </dependency>           
  </dependencies>
</plugin>

 

A few important points to note about this configuration:

  • The default username for Cargo is admin.
  • The default password is adminadmin. If you have no password, then use “” as Cargo will throw an error if the password field is empty.
  • The default admin port is 4848.
  • The default hostname is localhost.
  • The start and stop execution goals cannot be used with a remote Payara Server instance; this means that the remote instance MUST be running, otherwise Maven will fail.

Deploying to a Local Instance of Payara Server

To deploy to a local instance of Payara Server add the following to the profile you are using:

 
<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <container>
      <containerId>glassfish5x</containerId>
      <type>installed</type>
      <home>${payara.home}</home>
    </container>
    <configuration>
      <type>existing</type>
      <home>${payara.domainDir}</home>                 
      <properties>
        <cargo.glassfish.domain.name>${payara.domainName}</cargo.glassfish.domain.name>
      </properties>
    </configuration>
  </configuration>
  <!-- provides JSR88 client API to deploy on Payara -->
  <dependencies>
    <dependency>
      <groupId>org.glassfish.main.deployment</groupId>
      <artifactId>deployment-client</artifactId>
      <version>5.0</version>
    </dependency>
  </dependencies>
</plugin>

 

The full path to the Payara Server home, domains directory and domain name must be specified i.e.

  • payara.home=/path/to/payara5
  • payara.domainDir=/path/to/payara5/glassfish/domains
  • payara.domainName=domain1

 

Further information about the plugin is available at https://codehaus-cargo.github.io/cargo/GlassFish+5.x.html.

 

Comments

Subscribe

Themes

see all