WildFly
Overview
WildFly is the community edition of the Red Hat JBoss Enterprise Application Platform. It is a flexible, lightweight, managed application runtime that helps you build amazing applications. WildFly provides a robust environment for deploying Java applications, offering a range of features that support modern application development and deployment practices.
Deployment with WildFly
Manual Deployment
Before starting deployment, ensure that an instance of the WildFly application server is running. You can access the WildFly server management console by opening a browser window and navigating to http://localhost:9990. In the console, click on the Deployments menu and then the Upload Deployment button, as shown in Figure 9.2.
Figure 9.2 WildFly server Upload Deployment screen to upload a deployment
In the next window, upload the previously generated WAR file (e.g., course-tracker-app-war-1.0.0.war) from the target directory. Click the Next button, and then in the subsequent screen, click the Finish button. After successful deployment, you will see a confirmation message.
Automated Deployment with Maven
For frequent deployments, automating the deployment process can save time and reduce errors. The wildfly-maven-plugin is a useful tool for this purpose. To use this plugin, you need to add the associated configuration in your project's pom.xml file. Below is an example configuration:
Listing 9.13 Updated pom.xml file with wildfly-maven-plugin configuration
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/>
</parent>
<groupId>com.manning.sbip.ch09</groupId>
<artifactId>course-tracker-app-war-mvn-plugin</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>course-tracker-app-war-mvn-plugin</name>
<description>Spring Boot application for Chapter 09</description>
<properties>
<java.version>17</java.version>
<wildfly.deploy.user>${ct.deploy.user}</wildfly.deploy.user>
<wildfly.deploy.pass>${ct.deploy.pass}</wildfly.deploy.pass>
<plugin.war.warName>${project.build.finalName}</plugin.war.warName>
</properties>
<dependencies>
<!-- Dependencies omitted for brevity -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.1.0.Beta1</version>
<configuration>
<hostname>localhost</hostname>
<port>9990</port>
<username>${wildfly.deploy.user}</username>
<password>${wildfly.deploy.pass}</password>
<name>${project.build.finalName}.${project.packaging}</name>
</configuration>
<executions>
<execution>
<id>undeploy</id>
<phase>clean</phase>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<ignoreMissingDeployment>true</ignoreMissingDeployment>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Deployment Process
To deploy the application, navigate to the course-tracker-app-war-mvn-plugin directory in your terminal and execute the mvn install command. This will deploy the application, as shown in the following output:
Listing 9.15 The mvn install command output for successful deployment
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1:deploy (deploy) @ course-tracker-app-war-mvn-plugin ---
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
[INFO] --------------------------------------------------------------------
[INFO] BUILD SUCCESS
After deployment, you can access the application by opening a browser and navigating to http://localhost:8080. The index page of the Course Tracker application will be displayed, as shown in Figure 9.4.
Figure 9.4 The Course Tracker application index page. This page is served by the WildFly server.
Undeployment
If you need to undeploy the application, execute the mvn clean command. This will remove the deployed application, as shown in the following output:
Listing 9.16 Mvn clean to undeploy the deployed WAR file
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1:undeploy (undeploy) @ course-tracker-app ---
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
[INFO] --------------------------------------------------------------------
[INFO] BUILD SUCCESS
FAQ (Frequently asked questions)
What type of application runtime is WildFly?
What is the relationship between WildFly and Red Hat JBoss Enterprise Application Platform?
How can you upload a deployment in WildFly?
What does Figure 9.2 in the book depict?