JBoss WildFly

Wildfly Maven Plugin Example

This is an article about using the Wildfly Maven Plugin, a plugin developed by Red Hat that allows you to deploy, undeploy, and manage applications on a JBoss Wildfly Application Server.

You will get a brief introduction about how to install and use the plugin to communicate with your JBoss Wildfly Application Server.

The following table shows an overview of the entire article:

Table of Contents

1. Introduction

1.1 Wildfly Maven Plugin

The Wildfly maven plugin provides management operations, called Goals, that can be executed on a WildFly Application Server. The WildFly Maven Plugin is most often used to deploy applications or artifacts to a running WildFly Application Server. The commands are explicitly executed from the command line or specified in the execution portion of the plugin in the Maven Project Object Model (POM) file.  The plugin provides the following goals:

  • The wildfly:add-resource Goal – The wildfly:add-resource goal adds a resource to the running WildFly Application Server.
  • The wildfly:deploy Goal – The wildfly:deploy goal deploys the application to the running WildFly Application Server.
  • The wildfly:deploy-only Goal – The wildfly:deploy-only goal deploys the application to the running WildFly without executing any other goals by default.
  • The wildfly:deploy-artifact Goal – The wildfly:deploy-artifact goal deploys an arbitrary artifact to the running WildFly.
  • The wildfly:redeploy Goal – The wildfly:redeploy goal will redeploy your application if and only if the application has already been deployed to the application server.
  • The wildfly:redeploy-only Goal – The wildfly:redeploy-only goal will redeploy your application if and only if the application has already been deployed to the application server. By default no other goals are invoked.
  • The wildfly:undeploy Goal – The wildfly:undeploy goal will undeploy your application from the from the running application server if the application has already been deployed.
  • The wildfly:run Goal – The wildfly:run goal will run WildFly and deploy your application. If the wildfly.home property is not set, the server will be downloaded.
  • The wildfly:start Goal – The wildfly:start goal will start a WildFly. If the wildfly.home property is not set, the server will be downloaded. The server will be shutdown when the maven process ends unless an explicit shutdown was invoked.
  • The wildfly:shutdown Goal – The wildfly:shutdown goal will shutdown a running WildFly.
  • The wildfly:execute-commands Goal – The wildfly:execute-commands goal will execute commands, formatted like CLI commands, on the running server.

1.2 Wildfly

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 Logo
Wildfly Logo

1.3 Maven

Maven is a build automation tool used primarily for Java based projects. The Project Object Model (POM) is a core concept of Maven allowing it to manage a project’s build and the external dependencies used within the project.  Maven houses external dependencies in a central repository that is easily accessible.

Maven Logo
Maven Logo

2. Prerequisites

2.1 Wildfly Application Server

You will need a running Wildfly Application Server either deployed locally or on a cloud PaaS environment, such as Open Shift.  For a quick start on setting up a Wildfly Application Server on OpenShift, read my JBoss Wildfly Application Server Tutorial post.  For the sake of this tutorial, we will assume that your Wildfly Application Server is running on OpenShift.

Tip 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.

2.2 Maven Installation

You will need to have Maven 3.0 or 3.1.x installed locally on your system.  If you do not have Maven installed, download and install it.

2.3 Project Based on Maven Template 3.0 or 3.1.x

A project created from Maven template version 3.0 or 3.1.x and JDK 1.7 or higher is required.  When provisioning your Wildfly Application Server on OpenShift,  a starter Java web application is created and deployed for you.  The starter project already uses the version of Maven needed to follow the steps in this tutorial.

3. Installing the Plugin

To install the plugin, add wildfly-maven-plugin to your pom.xml as follows:

 
<plugin>

<groupId>org.wildfly.plugins</groupId>

<artifactId>wildfly-maven-plugin</artifactId>

<version>1.1.0.Alpha7</version>

</plugin>
Tip Pay close attention to where you place this plugin. Do not place it within the openshift profile! Ensure that it is placed at the highest level.

Place plugin here.
Place plugin here.

Do not place the plugin here.
Do not place the plugin here.

As of the writing of this tutorial, the latest version of the plugin is 1.1.0.Alpha7; however, feel free to use the latest version if it is different from the version covered in this tutorial.

To determine the latest version, go to the Maven repository for the WildFly Maven Plugin, which displays a screen similar to what’s shown below and identify the latest version.

Maven Repository
Maven Repository

Select the latest version and reference it in your POM by modifying the “version” number in the POM file to match the latest version.

4. Useful Features

In order to use the features of the Wildfly Maven plugin, ensure that you have setup port forwarding to your OpenShift Wildfly Application server and that you know the name of your application deployed to that server.

For my Wildfly Application Server,  the command is shown below, where “jbosswildfly” is the name of my application.

rhc port-forward jbosswildfly
Tip In order to use the rhc commands, you must have installed OpenShift’s RHC Command Line Tools. If you followed my JBoss Wildfly Application Server Tutorial post, RHC should already be set up.

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.

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.

4.1 Deploy an Application

The plugin allows you to deploy your application.

This command will deploy what is listed as the name parameter of the POM file to the Wildfly Application Server. In this case, the name is “jbosswildfly”.

Name parameter
Name parameter

In order to deploy your project, make sure that you are in the same directory where your pom.xml is placed and issue the deploy command:

mvn wildfly:deploy

Deploy User Name and Password
Deploy User Name and Password

You will be prompted for the administrative user name and password to your Wildfly Application Server, so enter those values when prompted.  A success screen is displayed upon entering valid credentials and your application is deployed.

Deployment Success
Deployment Success

4.2 Undeploy an Application

The plugin allows you to undeploy an application. In order to undeploy your application, make sure that you are in the same directory where your pom.xml is placed and issue the undeploy command:

mvn wildfly:undeploy

Undeploy Success
Undeploy Success

4.3 Add a Resource

The plugin allows you to add a resource, such as a database to your Wildfly Application Server.  In this example, we will review adding MySQL to a Wildfly Application Server.  The first step is to add the mysql dependency to your POM file.

Add a dependency
Add a dependency

The next step is to add the plugin for MySQL to your POM file.

Add a plugin
Add a plugin

After updating your POM, you are ready to deploy the artifact.  In order to deploy your artifact, make sure that you are in the same directory where your pom.xml is placed and issue the deploy command:

mvn wildfly:deploy-artifact

After a successful deploy, you can navigate to the administration panel for your Wildfly Application Server to ensure that the artifact was in fact deployed.

Deployment of artifact
Deployment of artifact

4.4 Stop the Application Server

The plugin allows you to stop your Wildfly Application Server. In order to stop the application server,  make sure that you are in the same directory where your pom.xml is placed and issue the shutdown command:

mvn wildfly:shutdown

Server Shutdown
Server Shutdown

A success screen is displayed and your Wildfly Application Server is shut down.

5. Conclusion

In this article we reviewed the Wildfly Maven Plugin, developed by Red Hat.  Instructions were provided on how to install and use the plugin to communicate with your JBoss Wildfly Application Server. We reviewed examples of deploying and undeploying an application, adding a resource, and stopping a JBoss Wildfly Application Server.

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.

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Hyewon
Hyewon
5 years ago

I deployed it successfully but I get 404 error. Someone please help me.

Ludovic
Ludovic
5 years ago
Reply to  Hyewon

No

Back to top button