As Jakarta EE 8 was now finally released on the 10th of September 2019, we can start using it. This is the first release of Jakarta EE and a big accomplishment as everything is now hosted at the Eclipse Foundation. The Eclipse Foundation hosted an online conference (JakartaOne) during the release day with a lot of interesting talks about the future of Jakarta EE. Stay tuned, as the talks will be published on Youtube soon! For now, there will be no new features compared to Java EE 8, but the plan is to have new features in Jakarta EE 9. With this blog post, I'll show you how to bootstrap your first Jakarta EE 8 application using Java 11 with both Maven or Gradle.
Use Maven to bootstrap your Jakarta EE application
To start with your first Maven Jakarta EE 8 project, your pom.xml
now needs the following jakartaee-api
dependency:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.rieckpil.blog</groupId> <artifactId>bootstrap-jakarta-ee-8-application</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> <version>8.0.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>bootstrap-jakarta-ee-8-application</finalName> </build> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <failOnMissingWebXml>false</failOnMissingWebXml> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> </project> |
During the online conference, Adam Bien also announced to create a new Maven archetype to bootstrap Jakarta EE 8 applications with a single command.
Use Gradle to bootstrap your Jakarta EE application
If you use Gradle to build your application, you can start with the following build.gradle
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | apply plugin: 'war' group = 'de.rieckpil.blog' version = '1.0-SNAPSHOT' repositories { mavenCentral() } dependencies { providedCompile 'jakarta.platform:jakarta.jakartaee-api:8.0.0' } compileJava { targetCompatibility = '11' sourceCompatibility = '11' } war{ archiveName 'bootstrap-jakarta-ee-8-application.war' } |
Sample Jakarta EE 8 application
As there are no new features for Jakarta EE 8 yet, you can make use of everything you know from Java EE 8. For a sample project, I'll create a JAX-RS application which fetches data from an external service and exposes them:
1 2 3 | @ApplicationPath("resources") public class JAXRSConfiguration extends Application { } |
1 2 3 4 5 6 7 8 9 10 11 12 | @Path("users") @ApplicationScoped public class UserResource { @Inject private UserProvider userProvider; @GET public Response getAllUsers() { return Response.ok(userProvider.getAllUsers()).build(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public class UserProvider { private WebTarget webTarget; private Client client; @PostConstruct public void init() { this.client = ClientBuilder .newBuilder() .readTimeout(2, TimeUnit.SECONDS) .connectTimeout(2, TimeUnit.SECONDS) .build(); this.webTarget = this.client.target("https://jsonplaceholder.typicode.com/users"); } public JsonArray getAllUsers() { return this.webTarget .request() .accept(MediaType.APPLICATION_JSON) .get() .readEntity(JsonArray.class); } @PreDestroy public void tearDown() { this.client.close(); } } |
For now, everything is still in the javax.*
namespace as there are no modifications, but once the specifications evolve, they will move to jakarta.*
.
Deploy your application
At the time of writing there are already three application servers officially Jakarta EE 8 Full Platform compatible: Glassfish 5.1, Open Liberty 19.0.0.6 and WildFly 17.0.1.Final. You can get an overview of all compatible products here.
For a quick example, I'll deploy the sample application to WildFly 17.0.1.Final running inside a Docker container:
1 2 3 4 5 6 7 | FROM jboss/wildfly:17.0.1.Final # Gradle # COPY build/libs/bootstrap-jakarta-ee-8-application.war /opt/jboss/wildfly/standalone/deployments/ROOT.war # Maven COPY target/bootstrap-jakarta-ee-8-application.war /opt/jboss/wildfly/standalone/deployments/ROOT.war |
To run the Jakarta EE 8 application on WildFly you don't have to configure anything in addition, it just works 😉
So if you are already familiar with Java EE 8, it's easy for you to adapt Jakarta EE 8. As we now have the Eclipse Foundation Specification Process (EFCP), we should see new features and platform releases way more often.
For further information about Jakarta EE, have a look at the official website.
The code for this example is available on GitHub.
Have fun using Jakarta EE,
Phil
Add the following dependency to your build.gradle
as providedCompile
jakarta.platform:jakarta.jakartaee-api:8.0.0