Deploying Applications From the Command Line

Payara Micro Community supports deploying applications directly from the command line.

Deploying an Application

As noted in the section Starting an Instance, all Payara Micro actions are run for the Payara Micro JAR, all in one command.

The general structure of starting, configuring, and deploying an application to an instance is as follows:

java -jar payara-micro.jar --option1 --option2 ...

Using Persistent Configuration Directory

When persistent configuration directory is reused across restarts (i. e. not running in a container), it is recommended not to specify deployment each time Payara Micro is invoked from that directory. Doing so will cause the application to be deployed twice — once at startup and second time when deployment section of the command line is processed.

The best approach if your application uses persistent filesystem is to use warmup run for deployment:

# perform deployments and configuration
java -jar payara-micro.jar --rootdir micro-root --warmup application.war

# all further invocations do not specify deployment
java -jar payara-micro.jar --rootdir micro-root

Alternatively a launcher can be generated for configured root directory as well:

# perform deployments and configuration
java -jar payara-micro.jar --rootdir micro-root --warmup application.war
java -jar payara-micro.jar --rootdir micro-root --outputlauncher

# all further invocations use parameterless launcher
java -jar micro-root/launch-micro.jar

Deploying an Application Package

To deploy a WAR file to an instance, you need to use the --deploy option, followed by the path to the application to deploy. See below for an example of starting a Payara Micro Community instance and deploying a WAR file:

java -jar payara-micro.jar --deploy /home/user/example.war
Since and 5.181 the --deploy option is optional if your deployment file ends with .jar, .rar or .war therefore the command line below can also be used
java -jar payara-micro.jar /home/user/example.war

Deploying an Exploded War

An exploded war can be deployed to a Payara Micro Community instance just be specifying the path to the exploded war root directory on the --deploy command line or via the API. The exploded war can be redeployed by creating a file .reload in the root directory of the exploded war and updating its timestamp for example using touch .reload in a LINUX machine.

Deploying Multiple Applications

If you want to deploy multiple applications to an instance with the --deploy option, you must use it once for each application to be deployed; it does not accept multiple paths.

For example, to deploy 2 applications:

java -jar payara-micro.jar --deploy /home/user/example.war --deploy /home/user/test.war

Alternatively, you can use the --deploymentDir option. This option specifies a directory to scan for deployable archives, allowing you to store all of the applications you wish to be deployed in a directory, and have them be deployed automatically upon instance startup.

java -jar payara-micro.jar --deploymentDir /home/user/deployments

Deploying Applications from a Maven repository

You can deploy an application directly from a Maven repository using the --deployFromGAV option. This option accepts a comma separated string denoting a Maven artefact’s groupId, artifactId, and version attributes.

java -jar payara-micro.jar --deployFromGAV "fish.payara.examples,test,1.0-SNAPSHOT"

This option can be used multiple times, and in conjunction with the standard --deploy options.

By default, Payara Micro will only search for artefacts in the Maven Central repository. If you wish to search additional repositories, you can add them to the list of repositories to search with the --additionalRepository option:

java -jar payara-micro.jar --deployFromGAV "fish.payara.examples,test,1.0-SNAPSHOT" --additionalRepository

To search through multiple additional repositories, you can simply specify the option multiple times:

java -jar payara-micro.jar --deployFromGAV "fish.payara.examples,test,1.0-SNAPSHOT" --additionalRepository --additionalRepository

Define context root

The context root of an application can be specified using the option --contextroot or by appending the path to the war-file name given with the --deploy parameter.

A context root set using the option --contextroot <context-path> applies to the applciation of the first --deploy parameter that does not already specify a context root with its --deploy option.

java -jar payara-micro.jar --deploy /home/user/example.war --contextroot hello-world

The root context of the example.war application is now set to /hello-world.

Alternatively the context root can be included in the argument to the --deploy option. It follows the path to the war file separated by File.pathSeparator:

  • --deploy <war-file>:<context-path> (Linux uses :)

  • --deploy <war-file>;<context-path> (Windows uses ;)

java -jar payara-micro.jar --deploy /home/user/example.war:hello-world

The above command again results in the effective root context /hello-world.

The two methods can also be used together:

java -jar payara-micro.jar --contextroot bar
    --deploy /home/user/example.war:foo
    --deploy /home/user/test.war

Here example.war is deployed in /foo while test.war is deployed in /bar.

--deploy example.war: is identical to --deploy example.war:/ and deploys to the effective context root / while --deploy example.war deploys to /example. It follows that leading / can be given but aren’t required. However, tailing / must not be given. Using --deploy example.war:/foo/ renders the URL <host>/foo/ inaccessible.