How to Deploy a Java App with the Wildfly Application Server
Wildfly is a modular, lightweight Java application server that is maintained by Red Hat and is free to deploy to your data center or third-party cloud host. We’ve covered the deployment of Wildfly on a Ubuntu Server 20.04 instance and now we’re going to take that a step farther and see how easy it is to deploy a Java application with the platform.
To make this work, you’ll need the following:
- A running instance of Wildfly
- A sample Java application to deploy
Before we demonstrate the actual deployment, we have to create a deployable Java application. For that, we’ll turn to the tried and true Hello, World!
Install the Java JDK
To create the Java application, we’re going to need a bit of help from the Java JDK. Since we’re demonstrating on Ubuntu, the installation of the Java JDK is quite simple. Log into your Ubuntu machine, open a terminal window, and issue the command:
sudo apt-get install default-jdk -y
The installation will take care of all the necessary dependencies. When it completes, you can verify the installation with:
You should see something like the following in the output:
openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.10)
OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)
Build a Java application
Next, we’re going to build a simple Java application. With Wildfly, you can deploy file types such as EJB-JAR, WAR, EAR, or any kind of standard archive (such as RAR). We’ll be creating a WAR archive for our Java deployment.
To being, create a new directory with the command:
Change into that newly created directory with the command:
In that directory create two more directories with the commands:
Next, create the index.jsp file with the command:
In that file, paste the following contents:
String title = “Hello World”;
<h2><%= title %></h2>
If you see this, the example war-file was correctly de>
<%= new java.util.Date() %>
You are from <%= request.getRemoteAddr() %>
background: no-repeat left center url(‘d>
Save and close the file.
Next, create the MANIFEST.MF file with the command:
In that file, paste the following:
Where NAME is your name.
Save and close that file.
Create the web.xml file with the command:
Paste the following contents into that file:
Save and close the file. If we issue the tree command, we’ll see the structure of your Java application looks like this:
│ └── MANIFEST.MF
With everything in place, we can now create a .war file with the command:
jar -cvf helloworld.war *
The options are:
- c – Create a new Jar archive.
- v – Generates verbose output.
- f – Sets the file name to what follows the option (in our case helloworld.war.
When the command completes, you’ll find the helloworld.war file in the directory.
Deploy the New Java Application
It’s now time to deploy our Hello, World! Java application. Log into your instance of Wildfly and, from the main page, click Start (under Deployments — Figure 1).
On the resulting page, drag the helloworld.war file into the Deployment pane on the left side (Figure 2).
Once the file has been uploaded, it’ll be listed in the Deployment pane (Figure 3).
Click on the helloworld.war entry to display the attributes of the application (Figure 4).
Within the details, you should see a link for the root of the application, listed as /helloworld. If you click on that link, it should take you to the running application (Figure 5).
You can deploy as many applications as you need and they can then be accessed from the server by way of a web browser and an address like http://SERVER:8080/APP/ (where SERVER is either the IP address or DOMAIN of the hosting server and APP is the name of the app. In our case, the app URL would be:
Anyone on your LAN should be able to access that application.
If you want to disable your deployed application, click the drop-down next to View and select Disable (Figure 6).
You can also undeploy an app by selecting Undeply from the same drop-down.
Wildfly is a very powerful and simple-to-use Java application server. If you’re looking to deploy a Java-based application to either your LAN, WAN, or from a third-party cloud host, this is a great place to start.