The Simplest Jakarta EE 8 Application

Now that Jakarta EE 8 has been released, several runtimes have been updated to support Jakarta EE 8. To showcase this, I've written the bare minimum required to deploy a Jakarta EE application onto any Jakarta EE compliant server (in this instance IBM's Open Liberty.

The majority of the code is the Maven pom.xml file as shown below.

<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.developinjava</groupId>
 <artifactId>simple</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>war</packaging>

 <properties>
  <failOnMissingWebXml>false</failOnMissingWebXml>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
 </properties>

 <dependencies>
  <dependency>
   <groupId>jakarta.platform</groupId>
   <artifactId>jakarta.jakartaee-api</artifactId>
   <version>8.0.0</version>
   <scope>provided</scope>
  </dependency>
 </dependencies>
</project>

This is a standard Maven pom.xml file with a single dependency on the Jakarta EE 8 API.

To ensure the project builds correctly, the <failOnMissingXml /> tag is added because the is no web.xml file. Additionally, the <maven.compiler.source /> and <maven.compiler.target /> tags are used to ensure the project is built with Java 1.8.

To show that Jakarta EE 8 works, we can write a simple servlet:

package com.developinjava.simple;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/hello")
public class HelloWorldServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HelloWorldServlet() {
    }

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
        throws ServletException, IOException {
        response.getWriter().append("Hello, World !");
    }
}

To deploy to Open Liberty, ensure that the application is defined within the server.xml file

<webApplication id="simple" location="simple.war" name="simple"/>

and that the Jakarta EE feature is enabled (we could just enable the minimal of features, but this shows how to enable the full Jakarta EE feature set).

<featureManager>
    <feature>javaee-8.0</feature>
</featureManager>

After deploying the application, we can show that it works by executing a HTTP GET request against the servlet endpoint

❯ curl http://localhost:9080/simple/hello
Hello, World !

Credits

Photo by (Maximilian Weisbecker)[unsplash.com/@maximilianweisbecker?utm_sour..

No Comments Yet