How to customize WildFly applications on Openshift

In this tutorial Java EE example application on Openshift we have deployed a sample Java EE application using a database on Openshift. We will explore now other possibilities such as running CLI commands as part of the Vuild process and include a set of custom modules and finally we will learn how to add artifacts directly into the deployments folder of the application server.

Injecting CLI commands when Building WildFly Applications

If you need a fine grained control over WildFly configuration on OpenShift we recommend using the S2I WildFly server customization hooks ( which includes:

  • Wildfly configuration files from the `<application source>/<cfg|configuration>` are copied into the wildfly configuration directory.
  • Pre-built war files from the `<application source>/deployments` are moved into the wildfly deployment directory.
  • Wildfly modules from the `<application source>/modules` are copied into the wildfly modules directory.
  • Execute WildFly CLI scripts by using the `` script.

In the first example, we will show how to execute a CLI script as part of the build process. This example (available here uses the following project structure:

$ tree -a

├── extensions
│   ├── configuration.cli
│   └──
├── pom.xml
├── .s2i
│   └── environment
└── src
    └── main
        └── webapp
            └── index.jsp
  • The `extensions/configuration.cli` contains the CLI commands to be executed.
  • The `extensions/` launches the CLI using the utility function `run_cli_script` available in the `/usr/local/s2i/` script of WildFly S2I Builder Image:
#!/usr/bin/env bash
source /usr/local/s2i/


run_cli_script "${S2I_CLI_SCRIPT}"

Finally, within the `.s2i/environment` folder we can set environment variables such as the location of extensions dir.

You can build the application and expose the service as follow:

$ oc new-app --as-deployment-config wildfly:26.0~ --context-dir=openshift/config --name demo-config

$ oc expose service/wildfly-config

By requesting the Route Address, you will see the System Property which has been injected with the CLI:

$ curl wildfly-config-wildfly.apps-crc.testing

  <body bgcolor=white>

  <table border="0" cellpadding="10">
         <h1>WildFly - sample OpenShift configuration</h1>
  <br />
  <p>Prints System Property from configuration: HelloWorld</p>

Adding custom modules and deployments to WildFly on Openshift

Our second application, available on github at, will show how to add external modules and deployments during the Source to Image process.

How to customize WildFly applications on Openshift

As you can see from the above picture, you can use the following folders:

  • modules: Place here modules just like you would do in a bare-metal installation of WildFly. They will be automatically uploaded on WildFly
  • deployments: Place here artifacts that are to be deployed on the application server.
├── modules
│   └── com
│       └── itext
│           └── main
│               ├── itext-5.0.5.jar
│               └── module.xml
├── pom.xml
└── src
    └── main
        ├── java
        │   └── com
        │       └── mastertheboss
        │           └──
        └── webapp
            ├── index.jsp
            └── WEB-INF
                ├── jboss-deployment-structure.xml
                └── web.xml

The module.xml loads the itext JAR file and uploads it into the application server.

<module xmlns="urn:jboss:module:1.1" name="com.itext">

        <property name="jboss.api" value="private"/>

        <resource-root path="itext-5.0.5.jar"/> 


In order to link the library with the application server add a jboss-deployment-structure.xml file:

      <module name="com.itext" />

To build the application on Openshift specify the root folder as Git Repository URL:

Next, specify the subfolder “openshift/modules” as path:

How to customize WildFly applications on Openshift

Here is the application in action:

How to customize WildFly applications on Openshift

That’s all. You can check the rest of the source code on Github:

Found the article helpful? if so please follow us on Socials