Using GAV deploy on Payara Micro (en)

This article is the translation that written in Japanese on 20th December 2016. The original article (Japanese) is here.

We can deploy WAR files on Maven repositories to Payara Micro directly. In this article, I'll show it by a sample. Using GAV deploy needs to prepare a Maven repository at once, but it's easy after preparing it.

1. Prepare: Create a WAR file and register to a Maven repository

At the first, we need to prepare a Maven repository to upload a WAR file. If you can use Maven Central repository, it's the best. (See also http://maven.apache.org/guides/mini/guide-central-repository-upload.html when to upload Maven Central) Otherwise, use Sonatype Nexus for building a Maven repository.

We may upload any WAR files that is able to run on Payara Micro. If you need, multiple WAR files can be deployed also GAV deploy. But using snapshot version is easy to happen a trouble, so I recommend to use release version.

2. How to use GAV deploy

I make a sample WAR file that output "Hello, world" using JAX-RS. The code is on https://github.com/khasunuma/helloweb/tree/version-1.0. It's already upload to a Maven repository I prepared.

Then run to following command line, and deploy and run the sample.

When writing the original articles, the latest version of Payara Micro is 4.1.1.164.

java -jar payara-micro-4.1.1.164.jar --deployFromGAV jp.coppermine.samples:helloweb:1.0.0 --additionalRepository http://repo1.cubiwano.org/repository/maven-public

Give groupId, artifactId and version of the WAR file by --deployFromGAV option. And if use the in-house repository (not Maven Central), give the URL by --additionalRepository option. (In this case, the URL is http://repo1.haswell.jp/repository/maven-public)

Attention: the Maven repository using the sample (repo1.cubiwano.org) is accept both HTTP and HTTPS but should use "HTTP" in GAV deploy.

If you open http://localhost:8080/helloweb/api/hello by a Web browser, it shall show "Hello, world".

Using Payara Micro API is following. (the complete code is on https://github.com/khasunuma/payaramicro-gav)

package jp.copermine.samples.payaramicro;

import fish.payara.micro.BootstrapException;
import fish.payara.micro.PayaraMicro;

public class GavDeploy {

    public static void main(String[] args) throws BootstrapException {
        // Required if not using Maven central repository 
        final String repositoryUrl = "http://repo1.cubiwano.org/repository/maven-public";
        
        // groupId , artifactId , version
        // if version is SNAPSHOT, it may not run well
        final String gav = "jp.coppermine.samples,helloweb,1.0.0";
        
        PayaraMicro.getInstance().addRepoUrl(repositoryUrl).addDeployFromGAV(gav).setNoCluster(true).bootStrap();
    }

}