The next major release of WildFly Bootable JAR (3.0.0) is going to bring a super interesting feature. You can use a Maven goal to achieve live reload of your applications. Let's check it out.
In order to use the live reload feature, you have to use the version 3 of the WildFly Bootable Jar plugin:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-jar-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
<configuration>
<feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#${version.server.bom}</feature-pack-location>
<layers>
<layer>jaxrs</layer>
<layer>management</layer>
</layers>
<excluded-layers>
<layer>deployment-scanner</layer>
</excluded-layers>
<plugin-options>
<jboss-fork-embedded>true</jboss-fork-embedded>
</plugin-options>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
By updating to the new plugin version, you can use the new "dev-watch" goal, which is supposed to build, deploy and watch for changes in your application.
Let's try it with a simple REST Service:
@Path("/")
public class SimpleRESTService {
@GET
public String hello()
{
return "Hello from Bootable JAR!\n ";
}
}
Now build and run your application with:
$ mvn wildfly-jar:dev-watch
Check the application endpoint:
$ curl http://localhost:8080/rest
Hello from Bootable JAR!
Now edit the Endpoint so that t returns a different String:
@GET
public String hello()
{
return "Hello from Bootable JAR changed!\n ";
}
As you save the file, you will see that the application is automatically re-deployed:
14:42:35,200 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 18) WFLYUT0022: Unregistered web context: '/' from server 'default-server'
14:42:35,206 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment ROOT.war (runtime-name: ROOT.war) in 7ms
14:42:35,228 INFO [org.jboss.as.server] (management-handler-thread - 4) WFLYSRV0009: Undeployed "ROOT.war" (runtime-name: "ROOT.war")
14:42:35,239 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "ROOT.war" (runtime-name: "ROOT.war")
14:42:35,345 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 18) RESTEASY002225: Deploying javax.ws.rs.core.Application: class com.mastertheboss.jaxrs.activator.JaxRsActivator
14:42:35,347 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 18) WFLYUT0021: Registered web context: '/' for server 'default-server'
14:42:35,352 INFO [org.jboss.as.server] (management-handler-thread - 4) WFLYSRV0010: Deployed "ROOT.war" (runtime-name : "ROOT.war")
Check again the application endpoint:
$ curl http://localhost:8080/rest
Hello from Bootable JAR changed!
As you can see, we managed to reload our application without any manual re-deployment. Pretty neat isn't it?
You can check the source code of this example here: https://github.com/fmarchioni/mastertheboss/tree/master/bootable-jar/dev-watch