How to execute CLI scripts in WildFly Bootable Jar

WildFly Bootable jar is a plugin that lets you run your WildFly applications into bootable microservice-like components. This tutorial covers how to execute CLI script during the packaging or at runtime, to customize your bootable JAR configuration.

There are two ways to run CLI management scripts on the top of your executable Bootable Jar:

  • Execute CLI scripts during the packaging of the bootable JAR
  • Execute CLI scripts on the top of a runnable JAR file

Before diving into the two operation modes, let’s create a sample JAX-RS application that can run as a Bootable JAR file:

package com.mastertheboss.jaxrs.service;

import java.util.ArrayList;
import java.util.List;

public class SimpleRESTService {

	public String helloProperty(@PathParam("name") final String name) {
		return "Hello " +System.getProperty(name);

This REST Endpoint returns the value of a System Property. We will use the CLI scripts to inject two System Properties.

To activate the JAX-RS endpoint, an Activator is needed:


public class JaxRsActivator extends Application {
   /* class body intentionally left blank */

Done with the application code, let’s add the pom.xml:

<?xml version="1.0"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

  <name>Demo REST Service</name>



As you can see, the wildfly-jar-maven-plugin has been added as a Maven plugin. Within this file, we have added a cli-sessions element so that a CLI script will be run during the packaging.

Here is the packagescript.cli:


Let’s build our application:

$ mvn clean install

[INFO] Executing CLI, Server configuration
WARN: can't find jboss-cli.xml. Using default configuration values.
[INFO] CLI scripts execution done.
[INFO] Executing CLI, CLI Session, scripts=[packagescript.cli], resolve-expressions=true, properties-file=null
     . . . . .
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.391 s
[INFO] Finished at: 2021-05-24T08:51:43+02:00
[INFO] ------------------------------------------------------------------------

Within the build log, there is evidence of the CLI script execution which has been completed.

We will now add another CLI script named runtimescript.cli:


Now let’s run the application passing as argument the “–cli-script” to allow the runtime execution of the runtimescript.cli:

java -jar target/rest-demo-bootable.jar --cli-script=runtimescript.cli

The application server will boot and the application (“rest-demo”) will be deployed in the ROOT context:

08:53:48,366 INFO  [] (Controller Boot Thread) WFLYSRV0010: Deployed "rest-demo.war" (runtime-name : "ROOT.war")
08:53:48,382 INFO  [] (Controller Boot Thread) WFLYSRV0212: Resuming server
08:53:48,383 INFO  [] (Controller Boot Thread) WFLYSRV0025: WildFly Full 23.0.0.Final (WildFly Core 15.0.0.Final) started in 1611ms - Started 160 of 166 services (33 services are lazy, passive or on-demand)
08:53:48,384 INFO  [] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on
08:53:48,384 INFO  [] (Controller Boot Thread) WFLYSRV0054: Admin console is not enabled

Let’s test the first property:

$ curl http://localhost:8080/rest/property/name
Hello john

And then the other:

$ curl http://localhost:8080/rest/property/surname
Hello Smith

As you can see, both System Properties have been injected by the CLI scripts.

Please note that Runtime execution of CLI scripts, passing as argument the “–cli-script“,  is available for WildFly 23 or newer.

Using Properties in CLI scripts

It is worth mentioning, that the Bootable Jar plugin allows to store CLI properties in a separate file, just like the tool does.

To do that, add a properties-file block in the cli-session element:


Then, in your CLI script, you can use properties:


The value of ${name} is resolved in the file


Source code for this demo: