Bootstrap a Jakarta EE 8 Maven project with Java 11 in seconds

Last Updated:  October 27, 2019 | Published: October 25, 2019

In one of my previous blog posts, I showed you what you need to create your first Jakarta EE 8 project. Manually creating a Maven project for a Jakarta EE application from scratch is cumbersome. Especially for new developers, the folder and file setup might be overwhelming. To overcome this manual process and to quickly bootstrap a new Jakarta EE 8 Maven project in seconds, I've created a Maven archetype. This includes all the necessary ingredients (Java 11, MicroProfile, JUnit, Mockito, etc.) to kickstart your new project.

Read this blog post to understand how to use this archetype and bootstrap your new Jakarta EE 8 projects in seconds.

Bootstrap a new project with a Maven archetype

First, you need Maven (at least version 3) available on your machine. You can download Maven here and just have to put the Maven binary on your path. Next, open a terminal window and use the following command to create the project:

HINT: Double-click on the code above to get the raw result to copy and paste it without any additional formatting.

You don't need to download anything in advance, as this command will download everything from Sonatype. It's important to specify the correct archetypeGroupId, archetypeArtifactId, archetypeVersion like in the example above.

Both the groupId and the artifactId are free to choose. As a basic convention, I'll use the artifactId for the folder name and the groupId for the initial package structure.

The interactiveMode attribute is optional but speeds up the process. Otherwise, you need to further confirm the creation of the project.

So the basic usage of this Maven archetype is the following:

Components of the pre-defined Jakarta EE 8 project

For the initial components of this Jakarta EE 8 project, I try to keep it to the bare minimum.  Alongside the Jakarta EE and MicroProfile specifications, JUnit 5 and Mocktio are available for efficient testing. Without further configurations, the pom.xml of the project looks like the following:

Furthermore, the project includes a basic persistence.xml, microprofile-config.properties, beans.xml file to start using JPA, CDI and MicroProfile Config.

In addition a first JAX-RS resource is available to ensure the package structure is created and the application is up- and running:

Build and deploy the application

As a default deployment target, you'll get Open Liberty. The project includes a Dockerfile to create a Docker container of your application running on Open Liberty:

The configuration for Open Liberty is basic, but enough and can be extended or reconfigured at any time:

HINT: For production usage, make sure to further adjust the security settings properly.

To serve the application from the root path, I'm including a ibm-web-ext.xml file with to configure the context root path:

Last but not least, you can build and deploy the application with a script for convenience. It's available for both Windows buildAndRun.bat) and Mac/Linux (buildAndRun.sh). Once you execute it, Maven will create the .war file and a new Docker container is spawned.

Once the application is up- and running, you can visit http://localhost:9080/resources/sample and should get a greeting.

In total, these are the required commands to have your next Jakarta EE 8 Maven project up in seconds:

Live demo of this Jakarta EE 8 archetype

If you are looking for further Maven archetypes to bootstrap a Java EE 8 project with or without JSF setup, have a look at the following tutorials:

You can find the archetype on GitHub.

Have fun creating new Jakarta EE 8 projects with Maven,

Phil

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join Our Mailing List To Get 3x Free Cheat Sheets

    Free Java Cheat Sheets
    >