How to create a JEE application with WildFly Swarm in two simple steps

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

Guess what, WildFly Swarm has been released and it's simpler than ever to configure and run your application as microservices. Let's create one basic application in a matter of minutes!

WildFly Swarm offers an innovative way to package and deliver Java EE application which does not need an available container where you have to provision your application. It's all there in a JAR file which can be executed as a standalone Java application. The only twist is adding swarm dependencies to your Maven project. This is now even simpler as you can use a Project generator to do it for you.

Using Swarm Project Generator

The Swarm Project generator is available at:

As you can see from the following picture, all is up to you is to choose the Maven project settings and the libraries needed to run your application:

swarm project tutorial wildfly

Simply type in the required dependencies and the Ajax text box will search for dependencies which match your search. Cool isn't it ?

When you are done, simply click on Generate Project which will download an empty Maven project which contains the pre-configured pom.xml with your dependencies. Let's see what has been created for us:

<project xmlns="" xmlns:xsi=""

  <name>Wildfly Swarm Example</name>




    <!-- Java EE 7 dependency -->
    <!-- Wildfly Swarm Fractions -->

Let's add a couple of classes to test our Project. At first an EJB:

package swarm.demo.ejb;

import javax.ejb.Stateless;

public class DemoEJB {

    public String greet(String str) {
        return "Hello " +str;

Next a Servlet calling the EJB:

package swarm.demo.servlet;


import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import swarm.demo.ejb.DemoEJB;

public class HelloServlet extends HttpServlet {

	@EJB DemoEJB ejb;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

As you can see there's nothing which binds you to WildFly Swarm environment. It's a basic Java EE project.

Building and running the Project

In order to execute, at first build the project with:

$ mvn package

Now you can run it in two ways: by using java -jar [yourproject]:

$ java -jar target/demo-swarm.jar

Or if you prefer by using Swarm plugin:

$ mvn wildfly-swarm:run

WildFly application server will start, embedding the demo application on the root context. You can test it by reaching the Servlet's URL: http://localhost:8080/Hello

Plenty of examples are available on github at: