#HOWTO: Bootstrap a Java EE 8 and Microprofile 2.0 Maven project in seconds

Manually creating a new Java EE Maven project can be quite cumbersome. Creating all required folders and files for a simple JAX-RS endpoint with a database access was quite error-prone in the past for me. I constantly mixed up WEB-INF and META-INF with its files and was tired of manually creating the project structure. The bootstrapping of a Spring Boot application on the other side is rather simple with the Spring Initializer. I wanted to have a similar bootstrapping experience with Java EE and so I created a custom Maven Archetype for bootstrap a Java EE 8 and Microprofile 2.0 application in seconds. In this blog post you will learn how to use this archetype for your own projects.

Using this Maven archetype you’ll get a fresh project with the following configurations:

  • Java EE 8 and Microprofile 2.0.1 dependencies
  • Mockito and JUnit dependencies for efficient testing
  • beans.xml with bean-discovery-mode="all" for ready to go dependency injection
  • persistence.xml configured for JTA persistence unit
  • microprofile-config.properties for internal configurations
  • a JAX-RS configuration class
  • a sample JAX-REST rest endpoint (/resources/sample)
  • a Dockerfile for Payara 5.183 deployment at the root path level
  • a script for a convenient Docker build and deployment for both Windows and Linux/Mac

To use this archetype and to be able to deploy the project you need the following tools:

  • Java 8 installation
  • Maven CLI (mvn) or the embedded Maven of the IDE of your choice
  • a running Docker daemon

The formal Maven command for creating a new project from my archetype looks like the following:

mvn archetype:generate -DarchetypeGroupId=de.rieckpil.archetypes \
    -DarchetypeArtifactId=javaee8 \
    -DarchetypeVersion=1.0.1 \
    -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 -DarchetypeVersion=1.0.1 -DgroupId=de.rieckpil.blog -DartifactId=javaee-8-microservice -DinteractiveMode=false

The result will look like the following:

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 with ./buildAndRun.sh just make it executable with chmod +x buildAndRun.sh.

After the Payara server successfully started, you can visit http://localhost:8080/resources/sample and see the result of the sample JAX-RS endpoint.

If you have any problems or improvements for this archetype, feel free to open an issue in the GitHub repository.

Have fun bootstrapping new applications with this archetype,

Phil

1 Comment

  1. Pingback: #HOWTO: JPA integrations tests with Java EE | Philip's Homepage

Leave a comment

Your email address will not be published. Required fields are marked *