JBoss WildFly is a Java server runtime that makes it possible to run Java web applications. To facilitate the development process, you can use WildFly Maven Plugin to run the web application we are working on using Maven right away, no need to build the source code into a .war file and then copy it to the deployment directory of JBoss WildFly. In this tutorial, I will show you how to use this WildFly Maven Plugin!
I will create a new Spring MVC project as follows:
Because in Maven Archetype huongdanjava-springmvc-archetype, I have defined to use the Maven Jetty plugin to run this application, so I will remove this plugin, instead, I will declare to use WildFly Maven Plugin as follows:
1 2 3 4 5 |
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> </plugin> |
By default, WildFly Maven Plugin will download and use the latest version of JBoss WildFly to run the application. You can specify the JBoss WildFly version that you want to use by declaring the configuration as follows:
1 2 3 4 5 6 7 8 |
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <version>30.0.0.Final</version> </configuration> </plugin> |
The information in the <version> tag above is the version of JBoss WildFly that you want to use.
For my example application with Spring framework 6.x running with Java 17 and Jakarta EE 9, only JBoss WildFly version 27.0.1.Final is suitable, so I will declare my example as follows:
1 2 3 4 5 6 7 8 |
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>4.2.0.Final</version> <configuration> <version>27.0.1.Final</version> </configuration> </plugin> |
Now, if you run this application with Maven goals as mvn clean package wildfly:run, you will see the following results in the Console:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
09:55:48,486 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0027: Starting deployment of "wildfly-maven-plugin-example-1.0-SNAPSHOT.war" (runtime-name: "wildfly-maven-plugin-example-1.0-SNAPSHOT.war") 09:55:51,330 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment wildfly-maven-plugin-example-1.0-SNAPSHOT.war 09:55:51,495 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 8.0.0.Final 09:55:51,843 WARN [org.wildfly.extension.microprofile.opentracing] (MSC service thread 1-5) WFLYTRACEXT0012: No Jaeger endpoint or sender-binding configured. Installing a no-op sender 09:55:51,858 INFO [io.jaegertracing.internal.JaegerTracer] (MSC service thread 1-5) No shutdown hook registered: Please call close() manually on application shutdown. 09:55:51,861 INFO [org.wildfly.microprofile.opentracing.smallrye] (MSC service thread 1-5) WFLYTRAC0001: Tracer initialized: JaegerTracer(version=Java-1.6.0, serviceName=wildfly-maven-plugin-example-1.0-SNAPSHOT.war, reporter=RemoteReporter(sender=NoopSender(), closeEnqueueTimeout=1000), sampler=ConstSampler(decision=true, tags={sampler.type=const, sampler.param=true}), tags={hostname=Khanhs-MacBook-Pro.local, jaeger.version=Java-1.6.0, ip=127.0.0.1}, zipkinSharedRpcSpan=false, expandExceptionLogs=false, useTraceId128Bit=false) 09:55:52,022 INFO [org.jboss.weld.Version] (MSC service thread 1-3) WELD-000900: 5.1.0 (Final) 09:55:53,361 INFO [io.undertow.servlet] (ServerService Thread Pool -- 10) No Spring WebApplicationInitializer types detected on classpath 09:55:53,374 INFO [io.undertow.servlet] (ServerService Thread Pool -- 10) Initializing Spring root WebApplicationContext 09:55:53,377 INFO [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 10) Root WebApplicationContext: initialization started 09:55:53,998 INFO [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 10) Root WebApplicationContext initialized in 620 ms 09:55:54,085 INFO [jakarta.enterprise.resource.webcontainer.faces.config] (ServerService Thread Pool -- 10) Initializing Mojarra 4.0.0.SP01 for context '/wildfly-maven-plugin-example-1.0-SNAPSHOT' 09:55:54,838 INFO [io.undertow.servlet] (ServerService Thread Pool -- 10) Initializing Spring DispatcherServlet 'appServlet' 09:55:54,838 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 10) Initializing Servlet 'appServlet' 09:55:55,445 INFO [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 10) Completed initialization in 607 ms 09:55:55,446 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 10) WFLYUT0021: Registered web context: '/wildfly-maven-plugin-example-1.0-SNAPSHOT' for server 'default-server' 09:55:55,489 INFO [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0010: Deployed "wildfly-maven-plugin-example-1.0-SNAPSHOT.war" (runtime-name : "wildfly-maven-plugin-example-1.0-SNAPSHOT.war") |
So our application has been deployed successfully. The context path of the application, as you can see in the log message above, is /wildfly-maven-plugin-example-1.0-SNAPSHOT!
The result when I request to the address http://localhost:8080/wildfly-maven-plugin-example-1.0-SNAPSHOT/ is as follows: