Jakarta EE 11 Hello World Example Application on WildFly

With the release of Jakarta EE 11, enterprise Java development takes another big step forward, bringing native support for Java 21, virtual threads, and modernized specifications. In this tutorial, we will explore how to build a lightweight, production-ready Jakarta EE 11 RESTful Web Service and deploy it seamlessly to WildFly.

We will construct a REST API using the jakarta.ws.rs namespace that produces JSON responses, using only standard Jakarta EE 11 specifications.

1. Configuring pom.xml Dependencies and Plugins

To compile against Jakarta EE 11, you need the official Web Profile or Full API dependency in your pom.xml. We will also include the wildfly-maven-plugin to streamline deployments directly from the command line.

<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>com.example.jakarta</groupId>
    <artifactId>jakartaee-hello-world</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.release>21</maven.compiler.release>
    </properties>

    <dependencies>
        <!-- Key Jakarta EE 11 Dependency -->
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-web-api</artifactId>
            <version>11.0.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- WildFly Maven Plugin for Deployment -->
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>5.0.1.Final</version>
            </plugin>
        </plugins>
    </build>
</project>

2. Creating the Jakarta REST Application Code

Next, let's write the application code. We need three simple components: an Application Activator, a Data Model, and a REST Endpoint.

Step 2.1: JAX-RS Application Activator

The HelloApplication class extends jakarta.ws.rs.core.Application[cite: 10] and defines the base REST path for the application[cite: 10]:

package com.example.jakarta.hello;

import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.ApplicationPath;

@ApplicationPath("rest")
public class HelloApplication extends Application {
    // Needed to enable Jakarta REST and specify path.
}

Step 2.2: Data Model Object

The Hello class represents our response object, which will automatically be converted to JSON[cite: 11]:

package com.example.jakarta.hello;

public class Hello {

    private String name;

    public Hello(String name) {
        this.name = name;
    }

    public String getHello(){
        return name;
    }
}

Step 2.3: REST Endpoint Resource

The HelloWorldResource handles incoming HTTP GET requests and produces a JSON response[cite: 11]:

package com.example.jakarta.hello;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

@Path("hello")
public class HelloWorldResource {

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    public Hello hello(@QueryParam("name") String name) {
        if ((name == null) || name.trim().isEmpty()) {
            name = "world";
        }

        return new Hello(name);
    }
}

3. Deploying to WildFly

Download the latest version of WildFly supporting Jakarta EE 11 and start the application server:

$ ./standalone.sh

Now, build and deploy the application in a single step using the WildFly Maven plugin:

$ mvn install wildfly:deploy

In your WildFly console logs, you will confirm the successful deployment:

INFO  [org.jboss.as.server.deployment] WFLYSRV0027: Starting deployment of "jakartaee-hello-world.war"
INFO  [org.jboss.as.jaxrs] WFLYRS0018: Explicit (or default) module name assigned to JAX-RS deployment: jakartaee-hello-world.war
INFO  [org.jboss.as.server] WFLYSRV0010: Deployed "jakartaee-hello-world.war" (runtime-name : "jakartaee-hello-world.war")

4. Testing the Jakarta EE 11 Endpoint

You can test the endpoint using curl from your terminal:

$ curl localhost:8080/jakartaee-hello-world/rest/hello?name=francesco

Expected Output:

{"hello":"francesco"}

Conclusion

Congratulations! You have successfully built and deployed a modern Jakarta EE 11 RESTful service on WildFly using native jakarta.* annotations and standard Java 21 features.

Source code for this tutorial is available on GitHub: https://github.com/fmarchioni/mastertheboss/tree/master/jakartaee/jakartaee-11-quickstart


Recommended Articles

Jakarta RESTful Web Services 4.0 Overview, Features & WildFly Testing

Discover Jakarta REST 4.0 features, improvements, and how to test on WildFly. Learn about new methods for enhanced control and media types.

Migrating from Java EE to Jakarta EE with WildFly 18

Learn how to migrate your Java EE applications to Jakarta EE with WildFly 18, including changes to configuration and dependency management.

Migrate Legacy Java EE/Jakarta EE 8 Applications to Jakarta EE 10 - Tools and Challenges

Learn about tools for migrating legacy Java EE/Jakarta EE 8 applications to Jakarta EE 10. Understand common challenges and solutions.

Get Started with Jakarta Model-View-Controller (MVC) for Jakarta EE Applications

Learn how to build HTML applications using the popular MVC pattern in Jakarta EE, including key differences from JSF.