[JAVA] I tried hot reloading with DevTools from Thorntail (formerly WildFly Swarm)

Overview

About Thorntail

In the future, WildFly Swarm will be renamed Thorntail and aim for growth that is not bound by WildFly.

Motivation

Until now, the development of the WildFly Swarm app has been difficult because it cannot handle hot reloads. WildFly Swarm had no choice but to create a UberJar (executable JAR) and run it with the java -jar command. WildFly Swawrm's UberJAR can easily range from tens of megabytes to over 100 megabytes, taking time to package in development. With the replacement of Thorntail, the Developer Tool is now available for hot reloading. (A mechanism that reloads only the changed class without packaging or redeploying the entire application while the application server is running)

Since I tried the function this time, I will write the execution procedure below along with the sample code.

procedure

Preparation

At the time of this writing, Thorntail was only available in SNAPSHOT version and had not been released to Maven Central, so $ HOME / .m2 can be used to resolve dependencies on Thorntail's SNAPSHOT version libraries and plugins. Add https://oss.sonatype.org/content/repositories/snapshots as a Snapshot repository to /settings.xml.

xml:$HOME/.m2/settings.xml


<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <snapshots />
          <id>ossrh</id>
          <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots />
          <id>ossrh</id>
          <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

I have posted the sample code I made on GitHub. https://github.com/sightseeker/thorntail-demo

I will omit the procedure to create a project from scratch.

Sample code checkout


git clone [email protected]:sightseeker/thorntail-demo.git && cd thorntail-demo

Only one JAX-RS (REST API) is written in the source.

├── pom.xml
└── src
    └── main
        ├── java
        │   └── com
        │       └── sightseekerstudio
        │           ├── MyApplication.java
        │           └── MyResource.java
        └── resources
            └── META-INF
                ├── application.properties
                └── beans.xml

The following procedure uses two terminal windows. (For Thorntail execution (A) and for the compilation process (B))

Launch Thorntail in development mode

Terminal A


#Initial build of app
mvn package

#Reload development mode and launch Thorntail
THORNTAIL_DEV_MODE=reload
./target/thorntail-demo-1.0-SNAPSHOT-bin/bin/run.sh

#The server log appears in the standard output

Make sure you can access the app (JAX-RS resource)

Access http: // localhost: 8080 with a browser etc. and confirm that Hello World is displayed.

Make the process of detecting changes and compiling them resident

I'm using the Fizzed Watcher Maven Plugin to set pom.xml so that compile works with change detection. The following command will run compile when a file change is detected.

Terminal B


mvn fizzed-watcher:run

Try changing the class of the JAX-RS resource

At this timing, try changing the Hello World character string of src / main / java / com / sightseekerstudio / MyResource.java with an editor or the like.

Then, the compilation is executed in terminal B, and then the class of MyResource that has been changed by compiling in terminal A is reloaded.

You can go to http: // localhost: 8080 again and see that the modified string is displayed.

Recommended Posts

I tried hot reloading with DevTools from Thorntail (formerly WildFly Swarm)
I tried Eclipse MicroProfile OpenAPI with WildFly Swarm
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried DI with Ruby
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried using JOOQ with Gradle
I tried morphological analysis with MeCab
I tried to interact with Java
I tried UDP communication with Java
I tried GraphQL with Spring Boot
I tried Flyway with Spring Boot
I tried customizing slim with Scaffold