Bootstrapping a new JSF can be quite cumbersome if you are new to Java EE. Even after weeks of training, I had to look up the anatomy of the or the correct folder structure. As the JSF technology is still a valid and reasoned choice for frontend development in enterprises, I've created a simple Maven archetype to bootstrap a ready-to-go JSF application in seconds.
If you are completely new to JSF, make sure you read one of my blog posts about this technology first: JavaServer Faces, Simple CRUD table with JSF 2.3, or this great book: The Definitive Guide to JSF in Java EE 8
UPDATE: You can find the latest version of this JSF archetype on GitHub. Since version 2.0.0 of this archetype, the application server of choice is Open Liberty.
What's included in the Maven archetype?
Using this Maven archetype you'll get a fresh project with the following dependencies and configurations:
- Java EE 8 API dependency
- Microprofile 3.3 dependency
- Primefaces 8.0 and all-themes dependency
- Omnifaces 3.6.1 dependency
- Mockito and JUnit 5 dependencies for efficient testing
web.xmlfor JSF development with
bootstrapas selected Primfaces theme
persistence.xmlconfigured for JTA persistence unit
index.xhtmlwith a backing bean
- a Dockerfile for the latest Open Liberty deployment at the root path level (“/”)
.gitignorewith a configuration for Java development with the IDE of your choice
- a script for a convenient Docker build and deployment for both Windows and Linux/Mac
Bootstrap a new JSF project
To use this archetype and to be able to deploy the project you need the following tools:
- Java 11+ installation
- Maven CLI (
mvn) or the embedded Maven of the IDE of your choice
- a running Docker daemon (optional, you can also deploy to a local application server)
The formal Maven command for creating a new project from my archetype looks like the following:
mvn archetype:generate -DarchetypeGroupId=de.rieckpil.archetypes \
-DgroupId=<your project Group Id> \
-DartifactId=<your project artifact Id>
With this command, you just have to fill in your
groupId and your
artifactId and you'll be prompted to enter a version number or use the default 1.0-SNAPSHOT version.
For an even faster creation, you can use the following command to bypass the interactive mode:
mvn archetype:generate -DarchetypeGroupId=de.rieckpil.archetypes -DarchetypeArtifactId=javaee8-jsf -DarchetypeVersion=2.1.1 -DgroupId=de.rieckpil.blog -DartifactId=jsf-app -DinteractiveMode=false
With this, you have a ready-to-go Maven project setup for your Java EE 8 application. To deploy the application you can execute the
buildAndRun.bat (for Windows) or
buildAndRun.sh (for Linux/Mac) file to create the
.war, build the Docker image, and start a container afterward. If you have issues with executing the
./buildAndRun.sh just make it executable with
chmod +x buildAndRun.sh.
Right now the
.war is about 5 MB big, as the additional JSF dependencies (Primefaces & Omnifaces) are packaged within the
.war. To make this leaner you can add the dependencies to the application server of your choice and mark the dependencies within the
<scope>provided</scope>. I'm also planning to do this with a custom Open Liberty Docker image in a future release of this archetype.
After the Payara server successfully started, you can visit
http://localhost:9080/ and see the sample JSF page which displays an injected MicroProfile config property.
YouTube tutorial for this archetype
Furthermore, I've recorded a video for YouTube to show you how to use the archetype:
If you have any problems or improvements for this archetype, feel free to open an issue in the GitHub repository. For bootstrapping a simple Java EE 8 with Microprofile 3.3 application, have a look at my other Maven archetype.
Have fun bootstrapping new JSF applications with this archetype,