[JAVA] Runnable Jar on WildFly (also known as UberJar or BootableJar)

What article

While investigating the current status of MicroProfile in preparation for the latest stage I saw a release note that Wildfly supports Bootable Jar. If it's Redhat, is it Wildfly as well as Quarkus or Thorntail? ?? When I was shocked, so I made an article

Who is it for

For those who have developed in Java. If you manage to use Maven, you should know about it before reading.

Release notes of the trigger

The Wildfly 21 release notes include:

Bootable JAR / Galleon Layers

The biggest thing in WildFly 21 is Jean-Francois Denise and the team have added GA-level > support for the Bootable JAR feature that we’ve been working on over the last two releases.

・ Original document https://www.wildfly.org/news/2020/10/13/WildFly21-Final-Released/

How wonderful.

What is an executable Jar (both UberJar and BootableJar)?

I don't think anyone who has only done SpringBoot has experienced it, but before the advent of SpringBoot, by (1) starting middleware called an application server and then (2) deploying application archive files (war, ear, etc.), the Web I was launching an application.

image.png

The application server here was Wildfly.

Recently, instead of starting the application server in advance, it has become possible to wrap the library required by the application server in an application archiver file (jar) and start it suddenly. It's easy.

image.png

By the way, Wildfly officially reads it as Bootable Jar, but I think that it is often called Uber Jar in the world. Uber has a German meaning like "engagement / simultaneity" and it comes from that. (I also learned this for the first time after checking this time)

Try

I thought I'd do a tutorial from the Wildfly official page, but I enjoy it. Wildfly can be selected as the Starter of MicroProfile, so I will start from there.

https://start.microprofile.io/ Go to and select MP3.3 (meaning to use MicroProfile version 3.3) and WildFly will appear in MicroProfile Runtime, so just select it and download it.

image.png

After unzipping the Zip file, the contents are as follows.

image.png

According to Readme.md

mvn package

And for the completed jar file

java -jar target/demo-jboss-wildfly.jar



 Hit on the command line to launch the app. It's too easy.
 The first time, the download of various libraries runs, so it is slow, but the application launch took only a few seconds.
 It's as fast as Spring Boot.

```Execution log
\$ java -jar target/demo-jboss-bootable.jar
20:38:48,068 INFO  [org.wildfly.jar](main) WFLYJAR0007: Installed server and application in /var/folders/1m/v_pnk3kd3hj0558d1z3nsnzh0000gn/T/wildfly-bootable-server4287071073176360181, took 1736ms
20:38:48,524 INFO  [org.wildfly.jar](main) WFLYJAR0008: Server options: [--read-only-server-config=standalone.xml]
20:38:48,632 INFO  [org.jboss.msc](main) JBoss MSC version 1.4.12.Final
20:38:48,641 INFO  [org.jboss.threads](main) JBoss Threads version 2.4.0.Final
20:38:48,801 INFO  [org.jboss.as](MSC service thread 1-3) WFLYSRV0049: WildFly Full 21.0.0.Final (WildFly Core 13.0.1.Final) starting
20:38:49,685 INFO  [org.wildfly.extension.microprofile.config.smallrye._private](ServerService Thread Pool -- 17) WFLYCONF0001: Activating WildFly MicroProfile Config Subsystem
20:38:49,690 INFO  [org.jboss.as.naming](ServerService Thread Pool -- 19) WFLYNAM0001: Activating Naming Subsystem
20:38:49,695 INFO  [org.wildfly.extension.microprofile.openapi.smallrye](ServerService Thread Pool -- 18) WFLYMPOAI0001: Activating Eclipse MicroProfile OpenAPI Subsystem
20:38:49,715 INFO  [org.jboss.as.jaxrs](ServerService Thread Pool -- 16) WFLYRS0016: RESTEasy version 3.13.2.Final
20:38:49,722 INFO  [org.xnio](ServerService Thread Pool -- 15) XNIO version 3.8.2.Final
20:38:49,741 INFO  [org.wildfly.extension.undertow](MSC service thread 1-7) WFLYUT0003: Undertow 2.2.2.Final starting
20:38:49,743 INFO  [org.jboss.as.naming](MSC service thread 1-2) WFLYNAM0003: Starting Naming Service
20:38:49,773 INFO  [org.xnio.nio](ServerService Thread Pool -- 15) XNIO NIO Implementation Version 3.8.2.Final
20:38:49,818 INFO  [org.wildfly.extension.io](ServerService Thread Pool -- 15) WFLYIO001: Worker 'default' has auto-configured to 8 IO threads with 64 max task threads based on your 4 available processors
20:38:49,865 INFO  [org.wildfly.extension.undertow](MSC service thread 1-6) WFLYUT0012: Started server default-server.
20:38:49,868 INFO  [org.wildfly.extension.undertow](MSC service thread 1-8) WFLYUT0018: Host default-host starting
20:38:49,902 INFO  [org.jboss.as.server.deployment.scanner](MSC service thread 1-3) WFLYDS0013: Started FileSystemDeploymentService for directory /var/folders/1m/v_pnk3kd3hj0558d1z3nsnzh0000gn/T/wildfly-bootable-server4287071073176360181/standalone/deployments
20:38:49,913 INFO  [org.jboss.as.server.deployment](MSC service thread 1-8) WFLYSRV0027: Starting deployment of "demo-jboss.war" (runtime-name: "ROOT.war")
20:38:49,996 INFO  [org.wildfly.extension.undertow](MSC service thread 1-5) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
20:38:50,552 INFO  [org.jboss.weld.deployer](MSC service thread 1-8) WFLYWELD0003: Processing weld deployment ROOT.war
20:38:50,959 INFO  [org.hibernate.validator.internal.util.Version](MSC service thread 1-8) HV000001: Hibernate Validator 6.0.21.Final
20:38:51,321 INFO  [org.jboss.weld.Version](MSC service thread 1-1) WELD-000900: 3.1.5 (Final)
20:38:51,488 INFO  [org.jboss.weld.Bootstrap](MSC service thread 1-3) WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
20:38:52,237 INFO  [org.wildfly.extension.microprofile.openapi.smallrye](MSC service thread 1-8) WFLYMPOAI0004: Registered MicroProfile OpenAPI endpoint '/openapi' for host 'default-host'
20:38:52,600 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n](ServerService Thread Pool -- 22) RESTEASY002225: Deploying javax.ws.rs.core.Application: class com.example.demo.jboss.DemojbossRestApplication$Proxy$_$$_WeldClientProxy
20:38:52,639 INFO  [org.wildfly.extension.undertow](ServerService Thread Pool -- 22) WFLYUT0021: Registered web context: '/' for server 'default-server'
20:38:52,641 INFO  [org.jboss.as.server](Controller Boot Thread) WFLYSRV0010: Deployed "demo-jboss.war" (runtime-name : "ROOT.war")
20:38:52,669 INFO  [org.jboss.as.server](Controller Boot Thread) WFLYSRV0212: Resuming server
20:38:52,671 INFO  [org.jboss.as](Controller Boot Thread) WFLYSRV0025: WildFly Full 21.0.0.Final (WildFly Core 13.0.1.Final) started in 4140ms - Started 139 of 144 services (22 services are lazy, passive or on-demand)

→ 4140msec !!!

image.png

The top page of the MicroProfile sample application was successfully displayed.

Actually, what I dropped with MicroProfile's Starter was not the Wildfly 21 I introduced at the beginning. Looking at pom.xml

...
<version.wildfly>19.1.0.Final</version.wildfly> 
...

It was 19.1, so it means that it was supported from that version. Since a new version came out, I changed it to 21 this time and moved it.

...
<version.wildfly>21.0.0.Final</version.wildfly>
...

Also, I thought that I had to change the plugin that makes Jar, but I don't know how to set it, so I'm running it without specifying the version for the time being.

...
      <build>
        <plugins>
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-jar-maven-plugin</artifactId>
            <!--I don't know what the latest version is, so I remove it and run it with the latest version-->
            <!--version>1.0.0.Alpha4</version-->
            <executions>
...

Summary

I thought that the recognition that the executable Jar can be realized with Wildfly is low, so I made an article. It may be difficult to change the product environment immediately in terms of operation, but changing from the local development environment I would like to take various steps, such as using it from prototype development.

reference

The source code used is posted on Github. It is for your reference. https://github.com/omix222/wildfly21demo

This is an article that summarizes the outline of MicroProfile in the past. https://qiita.com/omix222/items/50804e30e43085ceb912

Recommended Posts

Runnable Jar on WildFly (also known as UberJar or BootableJar)