Using WildFly Glow to provision a WildFly server for a RESTEasy based project
By Wei Nan Li | January 31, 2024
Recently I created a sample project showing the usage of the feature for deploying a RESTEasy based sample project1. The project contains a minimal REST based service and a test case, and it uses the maven-wildfly-plugin
to produce a provisioned WildFly server for the integration testing.
The maven-wildfly-plugin
has integrated WildFly Glow2 since 5.0.0.Alpha1
3. I have created the PR to the sample project to enable the feature4.
I’ll give some brief description to the above configuration. To use the Glow feature, first we need to add the following configuration to the wildfly-maven-plugin
:
<discover-provisioning-info>
<version>${version.wildfly}</version>
<failsOnError>false</failsOnError>
</discover-provisioning-info>
The above discover-provisioning-info
will enable the embedded Glow feature to scan the project source code and detect the layers to be used in the provisioned WildFly server. Next in the executions
section of the plugin, the package
goal needs to be added:
<execution>
<id>wildfly-glow-provision</id>
<goals>
<goal>package</goal>
</goals>
</execution>
To start the provisioned WildFly server and deploy the sample project before the integration testings and shutdown the server after the testings, add the following execution configuration:
<execution>
<id>wildfly-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<filename>resteasy-wildfly.war</filename>
</configuration>
</execution>
<execution>
<phase>post-integration-test</phase>
<id>wildfly-stop</id>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
In addition, if we need to separate the integration tests from the ordinary tests, we can configure these two plugins:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
The above setup will run the integration tests that has the name pattern **/*IT.java
and execute the tests during the integration-test
and verify
phases. After explaining the meaning of the configurations, you can run the project with the following command:
$ mvn verify
The above command will run the pre-integration-test
, integration-test
and the post-integration-test
phases. Here is part of the output generated by the above command related with Glow:
...
[INFO] Glow is scanning...
[INFO] Glow scanning DONE.
[INFO] context: bare-metal
[INFO] enabled profile: none
[INFO] galleon discovery
[INFO] - feature-packs
org.wildfly:wildfly-galleon-pack:30.0.1.Final
- layers
ee-core-profile-server
jaxrs
[INFO] Some suggestions have been found. You could enable suggestions with the --suggest option (if using the WildFly Glow CLI) or <suggest>true</suggest> (if using the WildFly Maven Plugin).
[INFO] Provisioning server in /Users/weli/works/resteasy-wildfly/target/server
[INFO] Resolving feature-packs
[INFO] Installing packages
[INFO] Resolving artifacts
[INFO] Generating configurations
...
From the above output we can see that the jaxrs
layer is detected automatically by the Glow scanning feature. The layer is detected by scanning the source code of the sample project, and it found the Jakarta REST annotations in the source code, so the jaxrs
layer is added in the provisioned server. Then the provisioned server will be started, and the integration tests will be run in the server, and finally the server will be stopped after the integration testing phase.
Above is the brief usage of the Glow feature to automate the server provision process.
References
Useful Links
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor