JBoss WildFly

JBoss Wildfly Application Server Tutorial

This is an article about using Wildfly 10, an application server formerly known as JBoss, developed by Red Hat.

You will get a brief introduction about how to install the application server on OpenShift’s cloud platform and deploy an application via the Eclipse Integrated Development Environment (IDE). You will also learn about managing the application server.

The following table shows an overview of the entire article:

Table of Contents

1. Introduction

1.1 Wildfly

wildflylogo
Wildfly 10 Logo

Wildfly, formerly known as the JBoss Application Server, is a free open-source application server that provides an environment in which applications can run. Wildfly is written in Java and was originally authored by JBoss but is now actively maintained by Red Hat. Wildfly implements the Java Platform, Enterprise Edition (Java EE) specification and version 10 supports Java 8. Because Wilfly is written in Java, it can run on multiple platforms.

Wildfly offers several noteworthy features:

  • Java Server Pages (JSPs)/Java Servlets
  • Clustering
  • Load Balancing
  • Enterprise Java Beans
  • Failover
  • Java Message Service (JMS) integration,
  • Java Naming and Directory Interface (JNDI),
  • Java Transaction API (JTA),
  • Java Authorization Contract for Containers,  (JACC) and JavaMail
  • Caching
  • ActiveMQ as JMS Broker
  • Server Side JavaScript
  • Migration Assistance from Older Systems
  • Automatic Pool Sizing

The main benefit of Wildfly over other application servers is that Wilfly provides a full Java Enterprise Edition (JEE) stack, including Enterprise JavaBeans and many other technologies used when building an enterprise level Java application.  The administrative console is also intuitive and easy to use.

1.2 OpenShift

maxresdefault
OpenShift by RedHat

OpenShift is Red Hat’s Platform-as-a-Service (PaaS) application hosting platform that makes it easy to run container-based web applications in the cloud. OpenShift offers a free tier that gives you the ability to run up to three applications.  If you need more than three, you will need to upgrade to a non-free tier that provides enhanced features.  However for the sake of this tutorial, the free tier will meet your needs.

A PaaS environment like OpenShift speeds up application development by allowing developers to focus on writing code and giving them the tools needed to manage and deploy applications in the cloud. OpenShift provides several benefits:

  • access to free containers for running web applications
  • automation of building and deploying applications
  • automatic application scaling
  • self-service platform and on-demand application stacks
  • multi-language support
  • popular frameworks
  • persistence
  • source code version management
  • integration with popular IDEs

1.3 Eclipse

eclipse-800x188
Eclipse Integrated Development Environment (IDE) by Eclipse Foundation

Eclipse is a well-known and respected Integrated Development Environment (IDE) developed by the Eclipse Foundation. Eclipse is beneficial to programmers because it aids in the development process by providing the following key features:

  • An easy to use graphical user interface that navigates through your code hierarchy.
  • Syntax highlighting that displays source code in a color code format to improve readability.
  • Code completion that makes recommendations on methods and parameters as you type.
  • Recommendations on how to fix errors and automatic error correction.
  • A graphical debugger that allows for line-by-line code inspection.
  • Single key compilation and execution of a program.
  • Automatic code generation for commonly used patterns.
  • Integration with source code version control repositories.
Tip
To learn more about the Eclipse IDE, read my Eclipse Tutorial for Beginners blog post.

2. Prerequisites

2.1 OpenShift Free Account

You will need an OpenShift account in order to complete the steps in this tutorial. If you do not have an OpenShift account, you can sign up for one on the OpenShift website.

2.2 OpenShift Client Tools

You will need the OpenShift Client Tools installed on your machine in order to complete the steps in this tutorial. If you do not have the client tools installed on your machine, follow the installation steps.

2.3 Eclipse IDE for Java Developers & OpenShift JBoss Tools

You will need the Eclipse IDE for Java Developers and the OpenShift JBoss Tools. If you do not have these tools installed, follow the installation instructions.

3. Install Wildfly in the Cloud

There are several options for installing a Wildfly cartridge on OpenShift:

  • RHC Command Line Tools
  • Eclipse OpenShift JBoss Tools plugin
  • OpenShift Web Console

This tutorial covers using the OpenShift Web Console to install the Widfly cartridge with a starter application. The first step is to login to your OpenShift Web Console.

webconsole
OpenShift Web Console

After accessing your OpenShift Web Console, a page displays showing your list of applications.

OpenShift: Application List
OpenShift: Application List

The next step is to click on “Add Application” to add a new application.

Click on "New Application"
Click on “Add Application”

After clicking on “Add Application”, a screen will display that shows a list of cartridges available.

List of Cartridges
List of Cartridges

For this tutorial, you need to add the Wildfly cartridge, specifically, Wildfly Application Server 10.

Select Widfly Application Server 10
Select Widfly Application Server 10

If you cannot easy locate the Wildfly cartridge, enter the word “Java” in the search box to limit the possible choices.

Wildfly Application Server 10
Search for Java

When you click on “Wildfly Application Server 10”, the cartridge page displays.

Catridge Page
Catridge Page

Enter an application name in the “Public URL” section.  For this example, I have entered “myjbosswidlfy”; however, you are free to enter whatever name you want for your application.

Application Name
Application Name

Click on “Create Application” and the application is created and the application detail page displays.

Create Application
Create Application

Several steps occur in the background when you click on “Create Application”:

  • The gear is provisioned.
  • The Wildfly cartridge is installed.
  • A demo web application is created and started.
Tip
A gear is nothing more than a secure container in which your code will run. When a new gear is provisioned, it is allocated memory, disk space, CPU, and network bandwidth. The free tier allows you up to 3 gears.

After the application is created, the application detail page displays.  Be sure to make a note of your administrator Username and Password as they will be required for additional setup steps later in the tutorial.

Administration Credentials Screen
Administration Credentials Screen

That is it; in just one easy step, you have installed the Wildfly application server!  The OpenShift PaaS platform saves you from having to download, install, and configure the application server locally, which can be very time consuming and problematic.

4. Access Wildfly Administrative Web Console

4.1 Port Forwarding

In order to access the Wildfly Administrative Web Console from your local machine, port forwarding must be setup. Ensure that you have followed the prerequisite to install RHC Command Line Tools before attempting to setup port forwarding. The “Administrative Credentials Screen” provides the command to setup port forwarding for your application.

Port Forwarding Command
Port Forwarding Command

In my example, the command is

rhc port-forward myjbosswildfly

When configuring port forwarding ensure the application is up and running before doing so. To setup port forwarding from your local ports to the ports running on my Wildfly instance at OpenShift, go to a command/terminal window and enter the port forward command.

Port forward command to enter in command/terminal window
Port forward command to enter in command/terminal window

The port forwarding command does several steps:

  • Check for available ports to forward
  • Automatically forward available ports to the Wildfly instance

After the ports have been successfully forward, a success screen displays.

Port forward success screen
Port forward success screen

The following ports are forwarded:

  • 8080 – normal web traffic
  • 9990 – administrative port for Wildfly

You may terminate port forwarding at anytime by entering “CTRL-C” in the command/terminal window.

You may now access the administrative console from your local machine by opening a web browser and entering in “http://127.0.0.1:9990/”.  You will be prompted to enter your administrative user name and password.

Administrative Login Screen
Administrative Login Screen

Once you supply the user name and password, you are brought to the Administrative Console main page.

Administrative Panel Main Page
Administrative Panel Main Page

From this page, you have several options available to you:

  • Deployments – Add and manage deployments
  • Configuration – Configure subsystem settings
  • Runtime – Monitor server status
  • Access Control – Manage user and group permissions for management operations
  • Patching – Manage WildFly patches

These options will be covered in greater detail later in this tutorial.  Our next step now is to access the application we created, “myjbosswidlfy”, from within the Eclipse IDE.

5. Connect to Wildfly Application from Eclipse

You may view the starter web application that was created for you when you provisioned your Wildfly cartridge by going to the application URL in  a web browser.  The previously created application was called, “myjbosswidlfy” and is accessible via the URL http://myjbosswildfly-javaprog2.rhcloud.com.  The web application homepage is shown below.

"myjbosswidlfy" Java starter application
Java starter application

If you are unsure of your application URL, you may click on the “Continue to application overview page” text from the “Administration Credentials” page.

Administration Credentials Screen
Administration Credentials Screen

When you click on “Continue to application overview page”, the application overview page will appear, which displays the URL to your application at the top of the page.

Application Overview Page
Application Overview Page

Now that we’ve accessed the web application via a browser, let’s review the source code by connecting to it from Eclipse. Ensure that you have followed the prerequisite to install the OpenShift JBoss Tools plugins within the Eclipse IDE before attempting to connect to your application .  Open your Eclipse IDE and create a new OpenShift Application by clicking on File->New->Other->OpenShift Application:

Open Shift Application
Open Shift Application

Enter your credentials:

Credentials
Credentials

Select “Use my existing OpenShift application”:

Existing Application
Existing Application

Select the application to locally clone and import into Eclipse:

Select Application Name
Select Application Name

Select “Use my existing OpenShift application”:

Application Name
Application Name

Select “Use default clone destination” and click “Finish”:

Clone existing
Clone settings

Your application is displayed in the Project Explorer:

Project Explorer
Project Explorer

6. Modify and Deploy Wildfly Application from Eclipse

Let’s modify our application and deploy the update to Wildfly.

Open the index.html page and add the text “from your Java Code Geeks Tutorial” to your header:

index.html
index.html

Deploy your application by going to your “Servers” tab in the bottom tabbed window of the Eclipse IDE:

Server Tab
Server Tab

Right click on your application name and click “Publish”:

Publish
Publish

The step to publish will check in your code changes to the Git repository that was automatically created when the starter application was provisioned to your Wildfly cartridge.

Tip
Git is distributed source code version control system used by application developers.

Enter a commit message and select “Commit and Publish”:

Commit
Commit

The “Console” tab displays the status of your deployment, which should end in a successful deployment status:

Console
Console

View the changes to your web application by refreshing your web browser:

Updated index.html
Updated index.html

7. Taking Control of Your Application Server

In order to adjust the settings for your application server, go back to the Administrative Console main page.

Administrative Panel Main Page
Administrative Panel Main Page

7.1 Manually Deploying An Application

OpenShift supports deployment of existing WAR files.  If you have an existing application that you want to deploy to your Wildfly application server, there are two steps that you must follow:

  • Use the add deployment wizard to deploy the application
  • After deploying the application, enable the deployment

Click on “Start”:

adminmainpage2
Click Start

The Start button displays the deployment wizard main screen:

Deploy
Deployment Wizard

Click the “Add” button in the upper left-hand corner, which displays the “New Deployment” popup.

newdeploy
New Deployment Popup

Click Next in order to choose a file to upload:

File Select
File Select

Choose your file, in this example, I am using sample.war.

sample.war
sample.war

Click “Next” to verify your upload:

Verify Upload
Verify Upload

Click Finish:

If your deployment is successful, you should see a message stating so.  When you see the deployment screen, click on your newly added WAR file on the left-hand side to ensure your deployment is enabled.  If you checked “Enable” on the Verify Upload screen, your application should be enabled.  If you application is not enabled, you will need to enable it by clicking the “View” button.

Enabled
Enabled

Test your Deployment by going to a browser window and entering the URL for your application:

Application URL
Application URL

The deployed application will display in your browser window:

Sample Application
Sample Application

7.2 Adding Application Dependencies

The starter Java web application that was deployed when the Wildfly cartridge was provisioned uses Maven to  download dependencies,  build, and deploy your application.

Tip
Maven is a build automation tool used primarily for Java projects.

You may find depencies that you would like to include in your project in the Maven Central Repository. The lines provided for the artifact need to be placed inside of the <dependencies></dependencies> section of your pom.xml file.
Here is an example of including the openshift-java-client dependency within my pom.xml.

<dependencies>
<dependency>
<groupId>com.openshift</groupId>
<artifactId>openshift-java-client</artifactId>
<version>2.7.0.Final</version>
</dependency>
</dependencies>

I can now develop against version 2.7.0 of the OpenShift Java client.

7.3 Adding a Database

You may add a database after your application is created by going to the “Configuration” section and selecting “Start” by the “Create a Datasource” link.

Datasource
Datasource

Select “Subsystems”->”Datasources”->”Non-XA”->”Add”

Non XA Datasource
Non XA Datasource

When clicking “Add”, the “Create Datasource” popup displays. Select “MySQL Datasource” and click “Next”:

Click Add
Click Add

Enter a name for your datasource and click “Next”:

Enter datasource name
Enter datasource name

Select the appropriate driver and click “Next”:

JDBC driver information
JDBC driver information

This would be the time to change the administrative password to something you can remember. Take note of “Connection Settings” and click “Next”.

Connection Settings
Connection Settings

After clicking “Next”, your datasource is created based on the name entered, “MySqlDS”.  Note that datasources are case-sensitive.

Datasource created
Datasource created

The environment properties for your database are shown below.

Environment Variable Name

Usage

OPENSHIFT_MYSQL_DB_HOST

The host name or IP address used to connect to the database.

OPENSHIFT_MYSQL_DB_PORT

The port the database server is listening on.

OPENSHIFT_MYSQL_DB_USERNAME

The database administrative user name.

OPENSHIFT_MYSQL_DB_PASSWORD

The database administrative user’s password.

OPENSHIFT_MYSQL_DB_SOCKET

An AF socket for connecting to the database (for non-scaled apps only).

OPENSHIFT_MYSQL_DB_URL

Database connection URL.

7.4 Log Files to Monitor Server Status

To review the log files for your Wildfly application server, go to the Runtime section and select “Start”:

Runtime Section
Runtime Section

Select “Standalone Server”:

Standalone Server
Standalone Server

Select “Log Files”:

Standalone Server: Log file
Standalone Server: Log file

Select “View”:

View of Log Files
View of Log Files

8. Conclusion

In this tutorial, we covered the JBoss Wildfly 10 Application Server. We reviewed installing the application server on OpenShift’s cloud platform and deploying an application via the Eclipse Integrated Development Environment (IDE). Additionally, we learned how to take control of the application server by manually deploying WAR files, adding application dependencies, adding a database, and reviewing log files.

Kesha Williams

Kesha Smith Williams, M.S., has taught courses in the Java Certification program at UC Irvine Extension and helped to develop the curriculum since 2008. She most recently earned the Distinguished Instructor Award in 2014. She has over 20 years of experience in web development using Java and Microsoft technologies. Her expertise includes web design, programming, systems analysis and design, and technical project management. She has served as Java consultant and corporate trainer to major corporations in the airline, medical, and restaurant industries. She has also worked with the U.S. Air Force and other government agencies in the same capacity.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
shriya
shriya
5 years ago

Kindly let me know how to deploy a java application on Wildfly 16, with JDK 11

Back to top button