How to use Payara Micro Maven Plugin (en)

Payara 172 has various new features that are highly cloud-focused. A part of them, Payara Micro Maven Plugin is provided. It's a small but useful tools to develop applications running on Payara Micro.

Previously, there is a problem that it's difficult to develop applications for Payara Micro without Payara Server because no IDEs support Payara Micro directly. Now it has solved to use Payara Micro Maven Plugin.

1. Preparing Payara Micro Maven Plugin

Latest version of Payara Micro Maven Plugin is 1.0.0-SNAPSHOT, thus it's not on Maven central repository. At first we check out from GitHub and build it.

$ git clone https://github.com/payara/maven-plugins
$ cd maven-plugins/payara-micro-maven-plugins
$ mvn install

2. Using Payara Micro Maven Plugin

Here is GAV of Payara Micro Maven Plugin.

KeyValue
groupId fish.payara.maven.plugins
artifactId payara-micro-maven-plugin
version 1.0.0-SNAPSHOT

Payara Micro Maven Plugin has three goals; payara-micro:bundle, payara-micro:start and payara-micro:stop.

GoalDescription
payara-micro:bundle Create Uber Jar
payara-micro:start Start the application on Payara Micro
payara-micro:stop Stop the application on Payara Micro

Then minimal description on pom.xml is here:

<build>
  <plugins>
    <!-- snip -->
    <plugin>
      <groupId>fish.payara.maven.plugins</groupId>
      <artifactId>payara-micro-maven-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
    </plugin>
    <!-- snip -->
  </plugins>
</build>

But minimal description has some problems.

  • We have to create a War file before run payara-micro:bundle. The goal assumes the War file exists.
  • Goal payara-micro:start doesn't use Uber Jar in default. The goal supports various option of Payara Micro, thus it's not specified to Uber Jar.
  • In default, this plugin uses Payara Micro 4.1.1.171. Unfortunately, this version cannot run on Windows platform because of its bug. (Therefore Payara Micro 4.1.1.171.0.1 was released instead of it.)

Then, I show effectively minimal description as follows:

<build>
  <plugins>
    <!-- snip -->
    <plugin>
      <groupId>fish.payara.maven.plugins</groupId>
      <artifactId>payara-micro-maven-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <executions>
        <execution>
          <goals>
            <goal>bundle</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <payaraVersion>4.1.2.172</payaraVersion>
        <useUberJar>true</useUberJar>
      </configuration>
    </plugin>
    <!-- snip -->
  </plugins>
</build>

This runs goal payara-micro:bundle with goal install. So that we may do only one step `mvn install` to build an application and create Uber Jar. (I think it's very useful, don't you?)

After the goal, it seems that there are two files in project-name/target.

  • application-name.war (e.g. helloweb-1.1.0.war)
  • application-name-microbundle.jar (e.g. helloweb-1.1.0-microbundle.jar)

The second is Uber Jar. We may run it either on CLI directly or via the plugin's goals; payara-micro:start and payara-micro:stop. The way to use the plugin can be integrated with any IDEs, so we're able to develop applications for Payara Micro easily even if we don't use Payara Server.

3. Conclusion

To use Payara Micro is very easy. Now Payara Micro is integrated with any IDEs by using Payara Micro Maven Plugin.

If you want to know more information, see Payara Micro Maven Plugin's page.

4. Appendix

To write this article, I use https://github.com/khasunuma/helloweb/ as a sample application. And build and run it using the plugin, it's logging in the console of my IDE as follows:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building helloweb 1.1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- payara-micro-maven-plugin:1.0.0-SNAPSHOT:start (default-cli) @ helloweb ---
[INFO] Starting payara-micro from path: C:\Users\Kenji\workspace\helloweb\target/helloweb-1.1.0-microbundle.jar
(snip)
[2017-06-15T21:43:17.604+0900] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1497530597604] [levelValue: 800] 
Instance Configuration
Host: lysithea.voyager.coppermine.jp
HTTP Port(s): 8080 
HTTPS Port(s): 
Instance Name: Aggressive-Batfish
Instance Group: MicroShoal
Hazelcast Member UUID 1fb214f2-ac78-454e-a52c-81faf0d4f8b3
Deployed: helloweb-1.1.0 ( helloweb-1.1.0 war /helloweb-1.1.0 )



[2017-06-15T21:43:17.606+0900] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1497530597606] [levelValue: 800] 
Payara Micro URLs
http://lysithea.voyager.coppermine.jp:8080/helloweb-1.1.0

'helloweb-1.1.0' REST Endpoints
GET	/helloweb-1.1.0/api/hello
GET	/helloweb-1.1.0/api/hello



[2017-06-15T21:43:17.606+0900] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1497530597606] [levelValue: 800] Payara Micro  4.1.2.172 #badassmicrofish (build 235) ready in 12,255 (ms)

Payara Micro 172 or later, it shows URLs and REST Endpoints in the end of starting log. So we're able to obtain the paths definitely.