Package your Primefaces application in a JAR with Thorntail

IMPORTANT: The Thorntail project (formerly known as WildFly Swarm) has reached End Of Life. The last announced release is the 2.7.0. You are recommended to evaluate a migration plan for your applications.

Here are some useful resources for your migration plan:


Thorntail can be used to right-size your Java EE applications in a JAR file that can be executed without prior installation of the application server. In this guide, we will learn how to run our Hello World primefaces example HelloWorld Primefaces with Thorntail.

In order to get started, we can generate a basic project which uses CDI and JSF, which are the two required dependencies to run our project. Reach the Thorntail generator at

Thorntail tutorial

Download the generated Maven project.

Adding the Backing Bean:

We will add to our basic project the source code from our original Hello World Primefaces example. Here is the Bean class:

package com.mastertheboss;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.enterprise.inject.Model;

public class Bean {
    private String word;
    private String anagram;
    public void generateAnagram() {
        Random rand = new Random();
        List<Character> characters = new ArrayList<Character>();
        for (char c : word.toCharArray()) {
        StringBuilder output = new StringBuilder(word.length());
        while (characters.size() != 0) {
            int randPicker = (int) (Math.random() * characters.size());
        this.anagram = output.toString();
    public String getAnagram() {
        return anagram;
    public void setAnagram(String anagram) {
        this.anagram = anagram;
    public String getWord() {
        return word;
    public void setWord(String word) {
        this.word = word;

And the basic index.xhtml page:

<!DOCTYPE html>
<html xmlns=""
    <h:form id="jsfexample">
        <p:panelGrid columns="2">
            <f:facet name="header">Anagram maker</f:facet>
            <h:outputLabel for="Word" value="Word" />
            <p:inputText id="Word" value="#{bean.word}" label="Word" />
            <h:outputLabel for="Anagram" value="Anagram" />
            <h:outputText id="Anagram" value="#{bean.anagram}" />
            <f:facet name="footer">
                <p:commandButton action="#{bean.generateAnagram}" update="Anagram"
                    value="Generate anagram" icon="ui-icon-check" style="margin:0" />

Within our pom.xml file, we will just specify to include Primefaces dependency, so that it can be bundler in the final JAR:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
   <name>Thorntail Example</name>

Testing the Thorntail application

Done with it, we can compile and install our application with:

$ mvn clean install

Now you can test your application, by overriding the default context with “primefaces-demo”:

$ java -jar target/demo-thorntail.jar -Dthorntail.context.path=primefaces-demo

As you can see from the following screen, we managed to port our Primefaces application on Thorntail in a snap!

Thorntail tutorial