- Hands-On Cloud Development with WildFly
- Tomasz Adamski
- 182字
- 2021-08-27 19:38:48
Using hollow JARs
You are able to configure the Maven plugin to build hollow JARs, which contain the swarm server without the actual application deployed on it. Let's return to the JAX-RS + CDI example again to show how it works.
The first thing that we will need to do is configure the Maven plugin:
(...)
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${version.wildfly.swarm}</version>
<!-- 1 -->
<configuration>
<hollow>true</hollow>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
(...)
The only thing that we have to do is to enable the hollow configuration parameter (1). When we build the application and navigate to our target directory, we will see the following output:
As you can see in the preceding screenshot, one directory ends with the -hollow-swarm suffix. This is our hollow jar without the deployed application. When running it, we must provide the name of the application that we will deploy on the created server. We will be able to do it in the following way:
java jar catalog-1.0-hollow-swarm.jar catalog-1.0.war
This will start the container and run our application. As a result, it will behave in the same way as the original example.