これは、なにをしたくて書いたもの?
前に、WildFly Maven Pluginのdevゴールを試してみるエントリーを書きました。
WildFly Maven Pluginのdevゴールで、Jakarta EEアプリケーションの開発を始める - CLOVER🍀
今回は、provisionゴールとpackageゴールを試してみたいと思います。
WildFly Maven Plugin
前のエントリーの繰り返しになりますが、WildFly Maven Pluginの紹介も少し。
WildFly Maven Pluginは、Gallenを使ってWildFlyサーバーをプロビジョニングし、WildFlyサーバーへのデプロイ、再デプロイ、
アンデプロイやアプリケーションの実行ができるMavenプラグインです。
The wildfly-maven-plugin is used to provision a server using Galleon, package your application in Galleon provisioned server, deploy, redeploy, undeploy or run your application.
WildFly Maven Plugin – WildFly Maven Plugin (wildfly-maven-plugin)
現バージョンは、4.2.0.Finalです。
- WildFlyの起動、停止
- WildFlyへのアプリケーションのデプロイ、再デプロイ、アンデプロイ
- WildFlyサーバーのプロビジョニング、アプリケーションを含んだWildFlyサーバーのプロビジョニング
- コンテナイメージの作成
- WildFlyサーバーへのリソースの追加、コマンドの実行
- WildFlyサーバーを起動し、アプリケーションのソースコードの変更を監視してビルド、再デプロイ
今回はWildFlyサーバーのプロビジョニングを行うprovisionゴール、アプリケーションも含めてプロビジョニングするpackageを試して
みたいと思います。
wildfly:provision
provisionゴールは、WildFlyサーバーをプロビジョニングするゴールです。
provisionゴールのドキュメントはこちら。
WildFly Maven Plugin – wildfly:provision
サンプルはこちら。
WildFly Maven Plugin – Provision a server
Galleonという仕組みを使って、必要なものだけを含むWildFlyを構成することができます。
Galleonというのは、ひとつ以上の製品(またはコンポーネント)で構成されたソフトウェアディストリビューションを作成および メンテナンスするために設計されたプロビジョニングツールです。
Galleonツールを使用して、インストールまたはアンインストールできるソフトウェア(プロジェクト、製品、コンポーネントなど)の
単位を「Feature Pack」と呼びます。Feature Packはzipアーカイブで、Feature Packの作成者によってMavenリポジトリなどに
デプロイされ、Galleonツールを介してユーザーが利用します。
今回は、このGalleonをWildFly Maven Pluginから使用することになります。
WildFlyを構築する際には、Feature Packを元にしたレイヤーを選択します。WildFlyで使えるレイヤーは、以下にまとまっています。
Galleon Provisioning Guide / Provisioning WildFly with Galleon / WildFly Galleon layers
基本的なレイヤーは「Basic Galleon Layers」として定義されています。
「Basic Galleon Layers」からよく使うものを組み合わせ、まとめたものが「Foundational Galleon layers」としても提供されています。
レイヤーには依存関係があり、あるレイヤーを指定すると依存関係のあるレイヤーも引き込まれます。
このあたりは、こちらでも触れているので興味があれば。
WildFly Bootable JARを作る時に指定するGalleon layer、Galleon feature-packというものを少し見てみたい - CLOVER🍀
wildfly:package
packageゴールは、WildFlyサーバーのプロビジョニングを行い、さらにアプリケーションもデプロイするゴールです。
packageゴールのドキュメントは、こちら。
WildFly Maven Plugin – wildfly:package
サンプルはこちら。
WildFly Maven Plugin – Package your application
WildFlyサーバーをプロビジョニングするので、こちらもGalleonが絡んできます。
ここからは、実際に試していってみましょう。
環境
今回の環境は、こちら。
$ java --version openjdk 17.0.8.1 2023-08-24 OpenJDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu122.04) OpenJDK 64-Bit Server VM (build 17.0.8.1+1-Ubuntu-0ubuntu122.04, mixed mode, sharing) $ mvn --version Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9) Maven home: $HOME/.sdkman/candidates/maven/current Java version: 17.0.8.1, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: ja_JP, platform encoding: UTF-8 OS name: "linux", version: "5.15.0-83-generic", arch: "amd64", family: "unix"
また、比較のためにWildFlyもダウンロードしておきます。今回は29.0.1.Finalを使います。
$ curl -OL https://github.com/wildfly/wildfly/releases/download/29.0.1.Final/wildfly-29.0.1.Final.zip $ unzip wildfly-29.0.1.Final.zip
展開後のサイズはこのくらいです。
$ du -sh wildfly-29.0.1.Final 291M wildfly-29.0.1.Final
準備
ひとまず、Mavenプロジェクトがないと始まりません。
まずはpom.xml
の基本的な構成から。
<groupId>org.littlewings</groupId> <artifactId>.....</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <dependencies> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-web-api</artifactId> <version>10.0.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>ROOT</finalName> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.4.0</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> <plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <version>29.0.1.Final</version> <server-config>standalone.xml</server-config> </configuration> </plugin> </plugins> </build>
WildFly Maven Pluginは、とりあえず足しただけにします。version
で使用するWildFlyのバージョンを(指定しないと最新安定版を使用)、
server-config
で使用する設定ファイルを指定しておきます。
ソースコードも用意しておきましょう。簡単なJakarta RESTful Web Services(JAX-RS)を使ったアプリケーションを作成しておきます。
src/main/java/org/littlewings/wildfly/maven/JaxrsActivator.java
package org.littlewings.wildfly.maven; import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.core.Application; @ApplicationPath("") public class JaxrsActivator extends Application { }
src/main/java/org/littlewings/wildfly/maven/HelloResource.java
package org.littlewings.wildfly.maven; 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 Jakarta EE!!"; } }
WildFlyサーバーをプロビジョニングする
まずは、provisionゴールから試してみましょう。
$ mvn wildfly:provision
こんな感じでプロビジョンニングが始まり、しばらく待っているとtarget/server
にWildFlyがプロビジョニングされます。
[INFO] --- wildfly:4.2.0.Final:provision (default-cli) @ ..... --- [INFO] Provisioning server in /path/to/target/server [INFO] Resolving feature-packs [INFO] Installing packages [INFO] Resolving artifacts [INFO] Generating configurations [INFO] Delayed generation, waiting...
target/server
はデフォルトのプロビジョニング先で、これはprovisioningDir
で変更できます。
$ ll target/server 合計 524 drwxrwxr-x 11 xxxxx xxxxx 4096 9月 19 22:48 ./ drwxrwxr-x 3 xxxxx xxxxx 4096 9月 19 22:48 ../ drwxrwxr-x 2 xxxxx xxxxx 4096 9月 19 22:48 .installation/ drwxrwxr-x 3 xxxxx xxxxx 4096 9月 19 22:48 .well-known/ -rw-rw-r-- 1 xxxxx xxxxx 364 9月 19 22:48 .wildfly-maven-plugin-provisioning.xml -rw-rw-r-- 1 xxxxx xxxxx 26530 9月 19 22:48 LICENSE.txt -rw-rw-r-- 1 xxxxx xxxxx 2161 9月 19 22:48 README.txt drwxrwxr-x 3 xxxxx xxxxx 4096 9月 19 22:48 appclient/ drwxrwxr-x 3 xxxxx xxxxx 4096 9月 19 22:48 bin/ -rw-rw-r-- 1 xxxxx xxxxx 19358 9月 19 22:48 copyright.txt drwxrwxr-x 6 xxxxx xxxxx 4096 9月 19 22:48 docs/ drwxrwxr-x 4 xxxxx xxxxx 4096 9月 19 22:48 domain/ -rw-rw-r-- 1 xxxxx xxxxx 431393 9月 19 22:48 jboss-modules.jar drwxrwxr-x 3 xxxxx xxxxx 4096 9月 19 22:48 modules/ drwxrwxr-x 6 xxxxx xxxxx 4096 9月 19 22:48 standalone/ drwxrwxr-x 2 xxxxx xxxxx 4096 9月 19 22:48 welcome-content/
最初にダウンロードしたWildFlyのディストリビューションと比較してみましょう。
$ diff -rq target/server wildfly-29.0.1.Final wildfly-29.0.1.Final のみに存在: .galleon target/server のみに存在: .wildfly-maven-plugin-provisioning.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: domain-ec2.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-activemq-colocated.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-azure-full-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-azure-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-core.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-ec2-full-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-ec2-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-genericjms.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-gossip-full-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-gossip-ha.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-jts.xml ファイル target/server/docs/examples/configs/standalone-minimalistic.xml と wildfly-29.0.1.Final/docs/examples/configs/standalone-minimalistic.xml は異なります wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-rts.xml wildfly-29.0.1.Final/docs/examples/configs のみに存在: standalone-xts.xml
ほぼ同じですね。
サイズもほとんど変わりません。
$ du -sh target/server 281M target/server
もちろん起動できます。
$ target/server/bin/standalone.sh 〜省略〜 22:53:57,345 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management 22:53:57,346 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990 22:53:57,348 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 29.0.1.Final (WildFly Core 21.1.1.Final) started in 3276ms - Started 280 of 522 services (317 services are lazy, passive or on-demand) - Server configuration file in use: standalone.xml
アプリケーションはデプロイされていません。
$ target/server/bin/jboss-cli.sh -c --command='ls deployment'
ここからは、Galleonレイヤーを指定してWildFlyを少しスリムにしてみましょう。
こんな感じにしてみました。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> <layers> <layer>jaxrs-core</layer> </layers> </configuration> </plugin>
WildFly 29.0.1.FinalのFeature Packを指定して
<feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs>
「Basic Galleon Layers」からjaxrs-core
を指定。端的に言うと、JAX-RSとServletが使えるくらいのレイヤーです。
プロビジョニング済みのディレクトリがあると、再度プロビジョニングを行ってくれないので1度削除。
$ mvn clean
プロビジョニング。
$ mvn wildfly:provision
ものすごく小さくなりました。
$ du -sh target/server 69M target/server
フルのWildFly 29.0.1.Finalと比べると、中身にもだいぶ差があります。
$ diff -rq target/server wildfly-29.0.1.Final wildfly-29.0.1.Final のみに存在: .galleon target/server のみに存在: .wildfly-maven-plugin-provisioning.xml wildfly-29.0.1.Final のみに存在: appclient wildfly-29.0.1.Final/bin のみに存在: .jbossclirc wildfly-29.0.1.Final/bin のみに存在: add-user.bat wildfly-29.0.1.Final/bin のみに存在: add-user.properties wildfly-29.0.1.Final/bin のみに存在: add-user.ps1 wildfly-29.0.1.Final/bin のみに存在: add-user.sh wildfly-29.0.1.Final/bin のみに存在: appclient.bat wildfly-29.0.1.Final/bin のみに存在: appclient.conf wildfly-29.0.1.Final/bin のみに存在: appclient.conf.bat wildfly-29.0.1.Final/bin のみに存在: appclient.conf.ps1 wildfly-29.0.1.Final/bin のみに存在: appclient.ps1 wildfly-29.0.1.Final/bin のみに存在: appclient.sh wildfly-29.0.1.Final/bin のみに存在: client wildfly-29.0.1.Final/bin のみに存在: domain.bat wildfly-29.0.1.Final/bin のみに存在: domain.conf wildfly-29.0.1.Final/bin のみに存在: domain.conf.bat wildfly-29.0.1.Final/bin のみに存在: domain.conf.ps1 wildfly-29.0.1.Final/bin のみに存在: domain.ps1 wildfly-29.0.1.Final/bin のみに存在: domain.sh wildfly-29.0.1.Final/bin のみに存在: elytron-tool.bat wildfly-29.0.1.Final/bin のみに存在: elytron-tool.ps1 wildfly-29.0.1.Final/bin のみに存在: elytron-tool.sh wildfly-29.0.1.Final/bin のみに存在: installation-manager.bat wildfly-29.0.1.Final/bin のみに存在: installation-manager.properties wildfly-29.0.1.Final/bin のみに存在: installation-manager.ps1 wildfly-29.0.1.Final/bin のみに存在: installation-manager.sh wildfly-29.0.1.Final/bin のみに存在: jboss-cli-logging.properties wildfly-29.0.1.Final/bin のみに存在: jboss-cli.bat wildfly-29.0.1.Final/bin のみに存在: jboss-cli.ps1 wildfly-29.0.1.Final/bin のみに存在: jboss-cli.sh wildfly-29.0.1.Final/bin のみに存在: jboss-cli.xml wildfly-29.0.1.Final/bin のみに存在: jconsole.bat wildfly-29.0.1.Final/bin のみに存在: jconsole.ps1 wildfly-29.0.1.Final/bin のみに存在: jconsole.sh wildfly-29.0.1.Final/bin のみに存在: jdr.bat wildfly-29.0.1.Final/bin のみに存在: jdr.ps1 wildfly-29.0.1.Final/bin のみに存在: jdr.sh wildfly-29.0.1.Final/bin のみに存在: launcher.jar wildfly-29.0.1.Final/bin のみに存在: wildfly-elytron-tool.jar wildfly-29.0.1.Final/bin のみに存在: wsconsume.bat wildfly-29.0.1.Final/bin のみに存在: wsconsume.ps1 wildfly-29.0.1.Final/bin のみに存在: wsconsume.sh wildfly-29.0.1.Final/bin のみに存在: wsprovide.bat wildfly-29.0.1.Final/bin のみに存在: wsprovide.ps1 wildfly-29.0.1.Final/bin のみに存在: wsprovide.sh wildfly-29.0.1.Final/docs のみに存在: contrib wildfly-29.0.1.Final/docs のみに存在: examples ファイル target/server/docs/licenses/licenses.html と wildfly-29.0.1.Final/docs/licenses/licenses.html は異なります ファイル target/server/docs/licenses/licenses.xml と wildfly-29.0.1.Final/docs/licenses/licenses.xml は異なります ファイル target/server/docs/licenses/wildfly-ee-feature-pack-licenses.html と wildfly-29.0.1.Final/docs/licenses/wildfly-ee-feature-pack-licenses.html は異なります ファイル target/server/docs/licenses/wildfly-ee-feature-pack-licenses.xml と wildfly-29.0.1.Final/docs/licenses/wildfly-ee-feature-pack-licenses.xml は異なります ファイル target/server/docs/licenses/wildfly-feature-pack-licenses.html と wildfly-29.0.1.Final/docs/licenses/wildfly-feature-pack-licenses.html は異なります ファイル target/server/docs/licenses/wildfly-feature-pack-licenses.xml と wildfly-29.0.1.Final/docs/licenses/wildfly-feature-pack-licenses.xml は異なります wildfly-29.0.1.Final/docs のみに存在: schema wildfly-29.0.1.Final のみに存在: domain wildfly-29.0.1.Final/modules/system/layers/base のみに存在: asm wildfly-29.0.1.Final/modules/system/layers/base/com のみに存在: carrotsearch wildfly-29.0.1.Final/modules/system/layers/base/com/fasterxml のみに存在: classmate wildfly-29.0.1.Final/modules/system/layers/base/com/fasterxml/jackson のみに存在: dataformat wildfly-29.0.1.Final/modules/system/layers/base/com/github のみに存在: ben-manes wildfly-29.0.1.Final/modules/system/layers/base/com/google のみに存在: code wildfly-29.0.1.Final/modules/system/layers/base/com/google のみに存在: protobuf wildfly-29.0.1.Final/modules/system/layers/base/com のみに存在: h2database wildfly-29.0.1.Final/modules/system/layers/base/com のみに存在: microsoft wildfly-29.0.1.Final/modules/system/layers/base/com のみに存在: nimbusds wildfly-29.0.1.Final/modules/system/layers/base/com のみに存在: squareup wildfly-29.0.1.Final/modules/system/layers/base/com/sun/xml のみに存在: fastinfoset wildfly-29.0.1.Final/modules/system/layers/base/com/sun/xml のみに存在: messaging wildfly-29.0.1.Final/modules/system/layers/base のみに存在: gnu wildfly-29.0.1.Final/modules/system/layers/base のみに存在: ibm wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: agroal wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: micrometer wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: netty wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: opentelemetry wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: reactivex wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: common wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: config wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: fault-tolerance wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: health wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: jwt wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: openapi wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: opentelemetry wildfly-29.0.1.Final/modules/system/layers/base/io/smallrye のみに存在: reactive wildfly-29.0.1.Final/modules/system/layers/base/io のみに存在: vertx wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: batch wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: ejb wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: faces wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: jms wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: persistence wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: resource wildfly-29.0.1.Final/modules/system/layers/base/jakarta/security のみに存在: enterprise wildfly-29.0.1.Final/modules/system/layers/base/jakarta のみに存在: transaction wildfly-29.0.1.Final/modules/system/layers/base/jakarta/xml のみに存在: soap wildfly-29.0.1.Final/modules/system/layers/base/jakarta/xml のみに存在: ws wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: api wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: batch wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: ejb wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: faces wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: jms wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: jws wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: orb wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: persistence wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: resource wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: rmi wildfly-29.0.1.Final/modules/system/layers/base/javax/security のみに存在: enterprise wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: sql wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: transaction wildfly-29.0.1.Final/modules/system/layers/base/javax のみに存在: wsdl4j wildfly-29.0.1.Final/modules/system/layers/base/javax/xml のみに存在: soap wildfly-29.0.1.Final/modules/system/layers/base/javax/xml のみに存在: stream wildfly-29.0.1.Final/modules/system/layers/base/javax/xml のみに存在: ws wildfly-29.0.1.Final/modules/system/layers/base のみに存在: net wildfly-29.0.1.Final/modules/system/layers/base/org のみに存在: antlr 〜省略〜 wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/clustering/web のみに存在: spi wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/clustering/web のみに存在: undertow wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/clustering のみに存在: weld wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: discovery wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: event wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: batch wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: bean-validation wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: clustering wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: core-management wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: datasources-agroal wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: discovery wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: ee-security wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: elytron wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: elytron-oidc-client wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: health wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: messaging-activemq wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: metrics wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: micrometer wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: microprofile wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: mod_cluster wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: opentelemetry wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: opentelemetry-api wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: picketlink wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: rts wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/extension のみに存在: security wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/http-client のみに存在: ejb wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/http-client のみに存在: transaction wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: iiop-openjdk wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: micrometer wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: microprofile wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: mod_cluster wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: openssl wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: reactive wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: elytron-http-oidc wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: elytron-jose-jwk wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: elytron-jose-util wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: elytron-jwt wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: elytron-tool wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security のみに存在: http wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security/jakarta のみに存在: client wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly/security/jakarta のみに存在: security wildfly-29.0.1.Final/modules/system/layers/base/org/wildfly のみに存在: transaction wildfly-29.0.1.Final/modules/system/layers/base のみに存在: software wildfly-29.0.1.Final/modules/system/layers/base のみに存在: sun wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-full-ha.xml wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-full.xml wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-ha.xml wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-load-balancer.xml wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-microprofile-ha.xml wildfly-29.0.1.Final/standalone/configuration のみに存在: standalone-microprofile.xml ファイル target/server/standalone/configuration/standalone.xml と wildfly-29.0.1.Final/standalone/configuration/standalone.xml は異なります wildfly-29.0.1.Final のみに存在: welcome-content
起動してみると、だいぶ軽くなったことも確認できたりします。
$ target/server/bin/standalone.sh
ここで、WARファイルを作成して
$ mvn package
デプロイ。
$ cp target/ROOT.war target/server/standalone/deployments
動作しますね。
$ curl localhost:8080/hello Hello Jakarta EE!!
もっとも、JAX-RSしか使わないなんていうことはないと思うので、もう少しいろいろと指定するのかなと思います。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> <layers> <layer>jaxrs-server</layer> <layer>management</layer> </layers> </configuration> </plugin>
ここでは、「Foundational Galleon layers」からjaxrs-server
も選んでみました。JAX-RS、CDI、JPAが使えるレイヤーです。
では、再プロビジョニング。
$ mvn clean $ mvn wildfly:provision
だいぶサイズが増えましたね。
$ du -sh target/server 133M target/server
こんな感じで、レイヤーを選んで好きにWildFlyを構成していくとよいと思います。
ちなみに、このようにFeature Packだけ指定すると、最初のようにほぼフルのWildFlyサーバーがプロビジョニングされます。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> </configuration> </plugin>
executions
/execution
を指定すると、mvn package
でWildFlyサーバーもプロビジョニングされるようになります。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> </configuration> <executions> <execution> <id>provision</id> <phase>package</phase> <goals> <goal>provision</goal> </goals> </execution> </executions> </plugin>
…ここまではしなくてもいいような気はしますが。
JDBCドライバーとデータソースも加える例。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> <feature-pack> <location>org.wildfly:wildfly-datasources-galleon-pack:5.0.0.Final</location> </feature-pack> </feature-packs> <layers> <layer>jaxrs-server</layer> <layer>management</layer> <layer>mysql-datasource</layer> </layers> </configuration> </plugin>
こちらはWildFly DataSources Galleon Feature Packを使用しています。
GitHub - wildfly-extras/wildfly-datasources-galleon-pack: WildFly Feature Pack for DataSources
実行例は、こちらを。
WildFly Maven Pluginのdevゴールで、Jakarta EEアプリケーションの開発を始める - CLOVER🍀
WildFlyサーバーのプロビジョニングとアプリケーションのデプロイをまとめて行う
次は、packageゴールを試してみたいと思います。
WildFly Maven Plugin – wildfly:package
サンプルはこちら。
WildFly Maven Plugin – Package your application
設定は最初に戻しておきます。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <version>29.0.1.Final</version> <server-config>standalone.xml</server-config> </configuration> </plugin>
実行。
$ mvn wildfly:package
すると、なんと失敗します。
[INFO] --- wildfly:4.2.0.Final:package (default-cli) @ ..... --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.151 s [INFO] Finished at: 2023-09-19T23:17:21+09:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:4.2.0.Final:package (default-cli) on project .....: No feature-pack has been configured, can't provision a server. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
エラーメッセージを見ると、Feature Packを指定していないのがダメなようです。
Feature Packを指定してみます。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> </configuration> </plugin>
もう1度実行。
$ mvn wildfly:package
今度はプロビジョニングされます。この指定だと、サイズはほぼフルですが。
$ du -sh target/server 281M target/server
また、以下のように警告が出力されており、デプロイ対象がないことになっています。
[WARNING] The project doesn't define a deployment artifact to deploy to the server.
package
ゴールを含めるのが良さそうです。
$ mvn clean package wildfly:package
すると、今度はWARファイルがデプロイ用のディレクトリにコピーされます。
[INFO] Copy deployment /path/to/target/ROOT.war to /path/to/target/server/standalone/deployments/ROOT.war
あとは起動すれば
$ target/server/bin/standalone.sh
アプリケーションがデプロイされた状態のWildFlyが起動します。
$ curl localhost:8080/hello Hello Jakarta EE!!
ゴールをそれぞれ指定するのが面倒な場合は、packageゴール実行時にexecutions
/execution
にwildfly:packageゴールも実行するように
指定すればよいと思います。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> </configuration> <executions> <execution> <id>provision-package</id> <phase>package</phase> <goals> <goal>package</goal> </goals> </execution> </executions> </plugin>
これで、mvn package
でwildfly:package
も含めて行われます。
あとはレイヤーですね。先程のprovisionゴールの時と同じようにlayers
/layer
を指定。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> <layers> <layer>jaxrs-server</layer> <layer>management</layer> </layers> </configuration> </plugin>
これで、カスタマイズされた構成+アプリケーションがデプロイされたWildFlyサーバーができあがります。
$ mvn clean package wildfly:package
ところで、packageゴールの場合はデプロイするアーティファクトの名前を変更できます。
以下でROOT.war
になるようにしていましたが、これをコメントアウト。
<!-- <finalName>ROOT</finalName> -->
runtime-name
で、デプロイ時のアーティファクト名を指定します。
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <feature-packs> <feature-pack> <location>wildfly@maven(org.jboss.universe:community-universe)#29.0.1.Final</location> </feature-pack> </feature-packs> <layers> <layer>jaxrs-server</layer> <layer>management</layer> </layers> <runtime-name>ROOT.war</runtime-name> </configuration> </plugin>
パッケージング。
$ mvn clean package wildfly:package
すると、以下のような出力が確認でき、デプロイ先にコピーする時にアーティファクト名が変わっていることが確認できます。
[INFO] Copy deployment /path/to/target/app-0.0.1-SNAPSHOT.war to /path/to/target/server/standalone/deployments/ROOT.war
こんなところでしょうか。
まとめ
WildFly Maven Pluginを使って、WildFlyをプロビジョニングしたり、その際にアプリケーションをデプロイ対象として含めたりして
みました。
WildFlyをMavenの設定で好きにカスタマイズできるので、便利ですね。WildFlyを小さく構成したい場合などに、使ってみるとよいのかなと
思います。