CLOVER🍀

That was when it all began.

WildFly Maven Plugin × WildFly GlowでプロビジョニングするWildFlyに管理CLIを含める

これは、なにをしたくて書いたもの?

このところ、WildFlyを使う場合はWildFly Maven PluginとWildFly Glowでプロビジョニングすることがほとんどです。

ただ、デフォルトでは管理CLIは含まれておらず、たまに使いたくなるのでプロビジョニングの際に含める方法をメモしておきます。

対象のWildFlyは35.0.1.Final、WildFly Maven Pluginは5.1.2.Finalとします。

環境

今回の環境はこちら。

$ java --version
openjdk 21.0.6 2025-01-21
OpenJDK Runtime Environment (build 21.0.6+7-Ubuntu-124.04.1)
OpenJDK 64-Bit Server VM (build 21.0.6+7-Ubuntu-124.04.1, mixed mode, sharing)


$ mvn --version
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: $HOME/.sdkman/candidates/maven/current
Java version: 21.0.6, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "6.8.0-53-generic", arch: "amd64", family: "unix"

サンプルアプリケーションを作る

ひとまずサンプルアプリケーションを作りましょう。Jakarta RESTful Web Services(以降JAX-RS)を使った
とても簡単なものにします。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.littlewings</groupId>
    <artifactId>wildfly-maven-plugin-provisioning-with-cli</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>wildfly-ee-with-tools</artifactId>
                <version>35.0.1.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>5.1.2.Final</version>
                <executions>
                    <execution>
                        <id>package</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <overwrite-provisioned-server>true</overwrite-provisioned-server>
                    <discover-provisioning-info>
                        <version>35.0.1.Final</version>
                    </discover-provisioning-info>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

mvn package時にプロビジョニングされるようにしています。

                <executions>
                    <execution>
                        <id>package</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>

JAX-RSの有効化。

src/main/java/org/littlewings/wildfly/glow/RestApplication.java

package org.littlewings.wildfly.glow;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/")
public class RestApplication extends Application {
}

JAX-RSリソースクラス。

src/main/java/org/littlewings/wildfly/glow/HelloResource.java

package org.littlewings.wildfly.glow;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String message() {
        return "Hello World";
    }
}

プロビジョニングします。

$ mvn package

これでWildFly GlowでプロビジョニングされたWildFlyを起動できます。

$ target/server/bin/standalone.sh

確認。

$ curl localhost:8080/hello
Hello World

OKですね。

1度WildFlyを停止します。

ここでtarget/server/bin配下を見ると、起動スクリプトなどがありますが管理系のスクリプトがありません。

$ ll target/server/bin
合計 96
drwxrwxr-x 2 xxxxx xxxxx  4096  2月 15 20:05 ./
drwxrwxr-x 8 xxxxx xxxxx  4096  2月 15 20:05 ../
-rw-rw-r-- 1 xxxxx xxxxx  4491  2月 15 20:05 common.bat
-rw-rw-r-- 1 xxxxx xxxxx 16611  2月 15 20:05 common.ps1
-rwxr-xr-x 1 xxxxx xxxxx  4405  2月 15 20:05 common.sh*
-rw-rw-r-- 1 xxxxx xxxxx    49  2月 15 20:05 product.conf
-rw-rw-r-- 1 xxxxx xxxxx 11777  2月 15 20:05 standalone.bat
-rw-rw-r-- 1 xxxxx xxxxx  3554  2月 15 20:05 standalone.conf
-rw-rw-r-- 1 xxxxx xxxxx  4386  2月 15 20:05 standalone.conf.bat
-rw-rw-r-- 1 xxxxx xxxxx  4063  2月 15 20:05 standalone.conf.ps1
-rw-rw-r-- 1 xxxxx xxxxx  2294  2月 15 20:05 standalone.ps1
-rwxr-xr-x 1 xxxxx xxxxx 13422  2月 15 20:05 standalone.sh*

ここに管理CLIなどを追加したいというのが今回のお題です。

wildfly-cliアドオンを追加する

結論を言うと、これはwildfly-cliアドオンを追加すると解決できます。

まずWildFly Maven Pluginの設定に<suggest>true</suggest>を追加します。

                <configuration>
                    <overwrite-provisioned-server>true</overwrite-provisioned-server>
                    <discover-provisioning-info>
                        <version>35.0.1.Final</version>
                        <suggest>true</suggest>
                    </discover-provisioning-info>
                </configuration>

この状態でプロビジョニングすると、アドオンが表示されます。

$ mvn package

こちらですね。

[INFO] suggestions
[INFO] * you could enable the following add-ons:
[INFO]   - clustering add-ons:
    - infinispan : Brings in infinispan caches.
    - jgroups-aws : Brings in JBoss Modules modules required to configure the 'aws.S3_PING' discovery protocol.
    - mod_cluster : Support for mod_cluster integration.
  - jaxrs add-ons:
    - openapi : Support for MicroProfile OpenAPI.
  - lra add-ons:
    - lra-coordinator : Support for MicroProfile LRA Coordinator.
  - management add-ons:
    - hal-web-console : Management Web console. Make sure to add an initial user.
    - jdr : Support for the JBoss Diagnostic Reporting (JDR).
    - wildfly-cli : Server command line tools: jboss-cli, add-user, elytron-tool.
  - observability add-ons:
    - health : Support for runtime health checks.
    - metrics : Support for base metrics from the WildFly Management Model and JVM MBeans.
    - micrometer : Support for Micrometer.
  - rpc add-ons:
    - grpc : Support for gRPC.
    - iiop : Support for IIOP.
  - security add-ons:
    - ssl : Support for the Undertow HTTPS listener.
  - web add-ons:
    - load-balancer : Support for Undertow configured as a load balancer.

この中にあるwildfly-cliというアドオンが今回のターゲットになります。

wildfly-cli : Server command line tools: jboss-cli, add-user, elytron-tool.

というわけで、アドオンにwildfly-cliを追加します。

                <configuration>
                    <overwrite-provisioned-server>true</overwrite-provisioned-server>
                    <discover-provisioning-info>
                        <version>35.0.1.Final</version>
                        <add-ons>
                            <add-on>wildfly-cli</add-on>
                        </add-ons>
                    </discover-provisioning-info>
                </configuration>

プロビジョニング。

$ mvn package

するとスクリプトが一気に増えます。

$ ll target/server/bin
合計 312
drwxrwxr-x 3 xxxxx xxxxx  4096  2月 15 20:15 ./
drwxrwxr-x 8 xxxxx xxxxx  4096  2月 15 20:15 ../
-rw-rw-r-- 1 xxxxx xxxxx   477  2月 15 20:15 .jbossclirc
-rw-rw-r-- 1 xxxxx xxxxx  2459  2月 15 20:15 add-user.bat
-rw-rw-r-- 1 xxxxx xxxxx  1517  2月 15 20:15 add-user.properties
-rw-rw-r-- 1 xxxxx xxxxx  1095  2月 15 20:15 add-user.ps1
-rwxr-xr-x 1 xxxxx xxxxx  2392  2月 15 20:15 add-user.sh*
-rw-rw-r-- 1 xxxxx xxxxx  4491  2月 15 20:15 common.bat
-rw-rw-r-- 1 xxxxx xxxxx 16611  2月 15 20:15 common.ps1
-rwxr-xr-x 1 xxxxx xxxxx  4405  2月 15 20:15 common.sh*
-rw-rw-r-- 1 xxxxx xxxxx  2438  2月 15 20:15 elytron-tool.bat
-rw-rw-r-- 1 xxxxx xxxxx  1867  2月 15 20:15 elytron-tool.ps1
-rwxr-xr-x 1 xxxxx xxxxx  2747  2月 15 20:15 elytron-tool.sh*
-rw-rw-r-- 1 xxxxx xxxxx  3441  2月 15 20:15 installation-manager.bat
-rw-rw-r-- 1 xxxxx xxxxx    22  2月 15 20:15 installation-manager.properties
-rw-rw-r-- 1 xxxxx xxxxx  4370  2月 15 20:15 installation-manager.ps1
-rwxr-xr-x 1 xxxxx xxxxx  2581  2月 15 20:15 installation-manager.sh*
-rw-rw-r-- 1 xxxxx xxxxx  1006  2月 15 20:15 jboss-cli-logging.properties
-rw-rw-r-- 1 xxxxx xxxxx  3313  2月 15 20:15 jboss-cli.bat
-rw-rw-r-- 1 xxxxx xxxxx   913  2月 15 20:15 jboss-cli.ps1
-rwxr-xr-x 1 xxxxx xxxxx  2742  2月 15 20:15 jboss-cli.sh*
-rw-rw-r-- 1 xxxxx xxxxx  3035  2月 15 20:15 jboss-cli.xml
-rw-rw-r-- 1 xxxxx xxxxx 71915  2月 15 20:15 launcher.jar
-rw-rw-r-- 1 xxxxx xxxxx    49  2月 15 20:15 product.conf
-rw-rw-r-- 1 xxxxx xxxxx 11777  2月 15 20:15 standalone.bat
-rw-rw-r-- 1 xxxxx xxxxx  3554  2月 15 20:15 standalone.conf
-rw-rw-r-- 1 xxxxx xxxxx  4386  2月 15 20:15 standalone.conf.bat
-rw-rw-r-- 1 xxxxx xxxxx  4063  2月 15 20:15 standalone.conf.ps1
-rw-rw-r-- 1 xxxxx xxxxx  2294  2月 15 20:15 standalone.ps1
-rwxr-xr-x 1 xxxxx xxxxx 13422  2月 15 20:15 standalone.sh*
drwxrwxr-x 2 xxxxx xxxxx  4096  2月 15 20:15 systemd/
-rw-rw-r-- 1 xxxxx xxxxx 68868  2月 15 20:15 wildfly-elytron-tool.jar

WildFlyを起動して

$ target/server/bin/standalone.sh

管理CLIで接続してみましょう。

$ target/server/bin/jboss-cli.sh -c

確認。

[standalone@localhost:9990 /] ls -l /subsystem
bean-validation
core-management
deployment-scanner
ee
elytron
io
jaxrs
jmx
logging
naming
remoting
request-controller
security-manager
undertow
weld

OKですね。

別解

他のアプローチとして、同じ効果のあるレイヤーがcore-toolsとしてBasic Galleon Layersに定義されています。

WildFly Maven Plugin / Packaging your application for the cloud / WildFly Layers

こちらをlayers-for-jndilayerに追加することで、プロビジョニングされるWildFlyに含めることもできます。

WildFly Maven Plugin × WildFly GlowでプロビジョニングするWildFlyに自動検出対象以外のレイヤーを追加する - CLOVER🍀

おわりに

WildFly Maven PluginとWildFly Glowを使っている時に、プロビジョニングするWildFlyに管理CLIを含める方法をメモして
おきました。

使用頻度は低いのですが、たまに使いたくなるので覚えておきましょう。