Payara Micro Context Path

When deploying an application to Payara Micro, the default context path for any web resources is defined by the name of the archive.

For example, if I deploy the archive PayaraRest-1.0-SNAPSHOT.war, the context root is defined as /PayaraRest-1.0-SNAPSHOT

$ java -jar payara-micro.jar --deploy  PayaraRest-1.0-SNAPSHOT.war
[Payara Micro 4.1]  Loading application [PayaraRest-1.0-SNAPSHOT] at [/PayaraRest-1.0-SNAPSHOT]

There are a few techniques however for changing the context of deployed applications in Payara Micro.

File Name

The simplest way of changing the context of a deployed application is to change the name of the archive being deployed. The context will be set to the name of the archive, for example:

$ mv target/PayaraRest-1.0-SNAPSHOT.war target/Renamed.war

$ java -jar payara-micro.jar --deploy target\Renamed.war
[Payara Micro 4.1]  Loading application [Renamed] at [/Renamed]


The context of a web application can also be changed using the standard Payara configuration xml, by adding an entry into the glassfish-web.xml file within the project.

<glassfish-web-app error-url="">
$ java -jar payara-micro.jar --deploy  PayaraRest-1.0-SNAPSHOT
[Payara Micro 4.1] Loading application [PayaraRest-1.0-SNAPSHOT] at [/PayaraRest]

Deploying via Code

Using Java code, its relatively straightforward to deploy an application using a few lines of code. First of all, add the dependencies to Payara Micro into your pom.xml


Applications can then be deployed by creating an instance of a PayaraMicroRuntime and calling its deploy() method. This method takes the name and the context path to deploy:

package com.davidsalter.payaradeployer;

import fish.payara.micro.PayaraMicro;
import fish.payara.micro.PayaraMicroRuntime;

public class Main {

    public static void main(String[] args) throws Exception {
        PayaraMicroRuntime instance = PayaraMicro.bootstrap();
        InputStream is = new FileInputStream("<path to>\PayaraRest-1.0-SNAPSHOT.war");
        instance.deploy("PayaraRest", "Programatically", is);

[Payara 4.1] Loading application [PayaraRest] at [/Programatically]

/ Deployments

One final point to note is that if you wish to deploy an application at the root context /, this can be achieved by renaming the deployment ROOT.war

$ mv target/PayaraRest-1.0-SNAPSHOT.war target/ROOT.war

$ java -jar payara-micro.jar --deploy target\ROOT.war
[Payara Micro 4.1] Loading application [ROOT] at [/]


In this article, I’ve shown a few different techniques for changing the deployment context for web applications in Payara Micro. Hopefully you’ll agree that these simple techniques can allow you to make useful changes to your microservice deployments.