Getting Started with Jakarta EE 11: Hello World

Photo of Luqman Saeed by Luqman Saeed

Introduction

The release of Jakarta EE 11 represents another significant milestone in the evolution of the Java Enterprise framework. With over 25 years of history since its first release in 1999, Jakarta EE has continuously evolved while maintaining its core principles of stability and enterprise-grade reliability.

Jakarta EE 11 builds upon the foundation established in previous versions, introducing new capabilities like Jakarta Data 1.0 while updating many existing specifications. The platform maintains the namespace consistency established in Jakarta EE 9 with the 'jakarta' package structure, maintaining a stable migration path for enterprise applications.

Since older technologies continue to be pruned and specifications evolve to meet modern development needs, Jakarta EE 11 represents the continued modernization of this mature platform. You can see Jakarta EE 11 as the latest evolution of Java Enterprise, incorporating decades of experience in supporting enterprise applications while adopting contemporary development practices.

Since Payara is dedicated to Jakarta EE, we've continued our 'Getting Started with Jakarta EE' blog series to introduce developers to the latest version. As tradition dictates, we'll start with the classic 'Hello World' example!

Setting Up with Maven

You can use Maven build tools to compile and package your Jakarta EE 11 application. With Maven Archetypes, you can bootstrap many types of applications. For the moment, there is no specific archetype for Jakarta EE 11 available. You can start from any other Maven project and adapt the pom.xml file or use the quickstart archetype as follows:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart

Alternatively, you can also scaffold a barebones Jakarta EE application from Payara Starter. You will need to download Payara Server Community 7 Alpha to run the example in this blog post. Payara Server Community 7 is our Jakarta EE 11 implementation that is currently in development, expected to be released in the coming weeks. 

Whichever scaffolding option you choose, these are the important parts of the Maven configuration for your Jakarta EE 11 project:

  1. Define the jakartaee-web-api dependency so that your project can use all the specs that are part of the Web Profile. For most projects, the Web Profile is sufficient, otherwise, you can use the jakartaee-api dependency that corresponds with the Full Profile.
  2. Use the scope provided as all the required code for Jakarta EE 11 is already available within the latest Payara Community 7 Alpha. They don't need to be included in your WAR file which makes the file small and efficient.
  3. Define the JDK version you want to use for your application. In this case, we use JDK 21 as Jakarta EE 11 officially requires JDK 17 as the minimum version. The configuration parameters to specify the Java version are maven.compiler.source and maven.compiler.target. Unless you have a very special case, JDK 21 should be preferred in most cases.
  4. Define the name of the WAR file that needs to be created by defining it in the <finalName> parameter.
  5. Do not forget to define the packaging type as war so that the Maven tool will generate a Web Archive. You also need to specify the configuration <failOnMissingWebXml>false</failOnMissingWebXml> as we do not need a web.xml file in this simple example. The file is optional for Jakarta EE but without the configuration property, the Maven WAR plugin will complain.

Your pom.xml could look like this for the Jakarta EE 11 Hello World example:

<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>fish.payara.jakarta.ee11.start</groupId>
  <artifactId>hello</artifactId>
  <version>1.0</version>
  <packaging>war</packaging>
  <dependencies>
     <dependency>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakarta.jakartaee-web-api</artifactId>
        <version>11.0.0</version>
        <scope>provided</scope>
     </dependency>
  </dependencies>

  <build>
     <finalName>hello</finalName>
  </build>
  <properties>
     <maven.compiler.source>21</maven.compiler.source>
     <maven.compiler.target>21</maven.compiler.target>
     <failOnMissingWebXml>false</failOnMissingWebXml>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

 

You are now ready to open the Maven Project in your favorite IDE and start coding your application.

Hello REST Endpoint

Now that we have a project created, we can develop the Hello World REST endpoint using Jakarta REST (formerly JAX-RS). REST endpoints are the modern standard for building web APIs and microservices. While Servlets still form the foundation of web applications, you’ll typically use higher-level frameworks like Jakarta REST for building HTTP-based services.

In one of the next Jakarta EE 11 blogs, we will explore more advanced REST features like content negotiation, validation, and data binding, but today we'll use the typical Hello World demo.

First, we need to create an Application class to bootstrap our REST endpoints:

@ApplicationPath("/api")
public class RestApplication extends Application {
}

 

Now, let's create our Hello World REST endpoint:

@Path("/hello")
public class HelloResource {
   @GET
   @Path("/world")
   @Produces(MediaType.TEXT_PLAIN)
   public Response sayHello() {
       return Response.ok("Hello World from Jakarta EE 11!").build();
   }
   @GET
   @Path("/json")
   @Produces(MediaType.APPLICATION_JSON)
   public Response sayHelloJson() {
       return Response.ok("{\"message\": \"Hello World from Jakarta EE 11!\"}").build();
   }

}

 

Some background information on the example

  • The @ApplicationPath annotation defines the base URI for all REST endpoints in your application. In our example, all endpoints will be accessible under /api/*.
  • The @Path annotation on the class level defines the resource path. Combined with the application path, our resource will be available at /api/hello/*.
  • The @GET annotation indicates that this method responds to HTTP GET requests. Other common annotations include @POST, @PUT, @DELETE, and @PATCH.
  • The @Path annotation on methods further refines the endpoint path. Our sayHello() method will be accessible at /api/hello/world.
  • The @Produces annotation specifies the media type that the method can produce. This enables content negotiation where clients can request different formats.
  • The Response class provides a builder pattern for creating HTTP responses with full control over status codes, headers, and entity content.
  • Multiple endpoints can be defined in the same resource class, each serving different purposes (like returning plain text vs JSON).

You can test your endpoints by accessing:

  • http://localhost:8080/your-app/api/hello/world for plain text response
  • http://localhost:8080/your-app/api/hello/json for JSON response

Conclusion

Getting started with Jakarta EE 11 is straightforward. You just have to define one single dependency for your application that brings in the entire API set of Jakarta EE. We have shown how a Hello World response can be sent back from the server using Jakarta REST and in the next parts of this beginners Jakarta EE 11 series, we will see how other frameworks like Jakarta Persistence, CDI, and Jakarta Faces integrate with REST services to build complete enterprise applications.

What's New in Jakarta EE 11

Jakarta EE 11 introduces several enhancements:

  • Updated Java SE Requirement: Now requires Java SE 17 as the minimum version
  • Jakarta Data 1.0: New specification for data access patterns
  • Enhanced specifications: Updates to most existing specifications including Jakarta Servlet 6.1, Jakarta Faces 4.1, and Jakarta Persistence 3.2
  • Continued modernization: Removal of legacy technologies and enhancement of existing ones

The platform continues to evolve while maintaining the stability and enterprise-grade features that have made Jakarta EE the choice for mission-critical applications worldwide. Get started with Jakarta EE 11 by downloading Payara Server Community 7 Alpha today!

Related Posts

Comments