Payara Community 5.2020.5 has introduced tech preview functionality to run Jakarta EE 9 on Payara Server and Micro, more details please go to the release notes.

Originally Payara was a fork of the open-sourced Glassfish, but it includes a bundle of new features that not existed in Glassfish.

  • Numerous improvements and quicker bugfixes in comparison to the existing Glassfish
  • Java 11(or above) support
  • Built-in Microprofile support and ready for cloud native applications
  • Many third-party services integration.
  • Comprehensive documentation and technical guides
  • Commercial support available for paid enterprise users.

Payara Community is also open sourced, for developers, you use it as an alternative to Glassfish to get better development experience.

Prerequisites

Make sure you have installed the following software.

Deploy to local Payara server

Cargo maven plugin provides a separate payara container for Payara server.

Assume you have downloaded a copy of Payara Community dist, and extracted the files into your local disk.

Add the following configuration in pom.xml to use the existing Payara domain configuration to run your Jakarta EE 9 applications on the local Payara server.

<properties>
<glassfish.home>[ Payara install dir]</glassfish.home>
<glassfish.domainDir>${glassfish.home}/glassfish/domains</glassfish.domainDir>
<glassfish.domainName>domain1</glassfish.domainName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>payara</containerId>
<type>installed</type>
<home>${glassfish.home}</home>
</container>
<configuration>
<type>existing</type>
<home>${glassfish.domainDir}</home>
<properties>
<cargo.glassfish.domain.name>${glassfish.domainName}</cargo.glassfish.domain.name>
<cargo.remote.password></cargo.remote.password>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>

The above configuration is almost same as the one we have discussed in previous Glassfish post, but we used containerId payara here.

Open a terminal, execute the following command to run your application on the Payara server.

mvn clean package cargo:run -Ppayara-local

The above command will execute a serise of tasks.

  • Build the project and package it into a war archive in the target folder
  • Starts up Payara server using the existing domain1 configuration
  • Deploy the packaged war to the running server

If you want to use a refresh domain configuration every time to run your applications, try to set the configuration type to standalone. Change the server configuration section to the following.

<configuration>
<type>standalone</type>
<properties>
<cargo.remote.password></cargo.remote.password>
</properties>
</configuration>

A little different from the existing configuration, it will create a new domain configuration in the target folder instead of the default domain1 in the Payara server.

In the CI service, such as Github actions, I would like use the official maven-dependency-plugin to prepare a refresh copy of Payara server.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>fish.payara.distributions</groupId>
<artifactId>payara</artifactId>
<version>${payara.version}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Change the glassfish.home property to the following.

<glassfish.home>${project.build.directory}/payara5</glassfish.home>

To stop the server, just send a CTRL+C to the running console to stop it.

Deploy to a running Payara server

Use a remote deployer and runtime configuration, you can use Cargo maven plugin to deploy the application to a running Payara, esp. the Payara server is located in a remote server.

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

The above configuration is almost same as the one from Glassfish doc.

For a remote server, you can not start and stop the Payara server. Before deploying applications, make sure it is running and accessible from your local environment.

Use deploy and undeploy goals to perform the deploy and undeploy tasks.

# deploy applications
mvn clean package cargo:deploy -Ppayara-remote
# undeploy
mvn cargo:undeploy -Ppayara-remote

Verifying the deployed application

When the application is deployed successfully, you use curl to verify if the deployed application.

curl http://localhost:8080/jakartaee9-starter-boilerplate/api/greeting/Hantsy
{"message":"Say Hello to Hantsy at 2020-11-14T15:56:10.099"}
Note: In fact, you can use the glassfish5x containerId to deploy Jakarta EE 9 applications to Payara server, and in reverse I think it is also fine when using the payara containerId to deploy the application to Glassfish v6.

Grab the source codes from my github.


Deploying Jakarta EE 9 applications to Payara using Cargo maven plugin was originally published in ITNEXT on Medium, where people are continuing the conversation by highlighting and responding to this story.