Skip to main content

Migrate to Jakarta EE 10.0

In this tutorial, we'll use OpenRewrite to perform an automated migration to Jakarta EE 10. Jakarta EE 10 is packed with new features for building modernized, simplified, and lightweight cloud native Java applications. This new innovative community-driven release is designed for organizations looking to start developing new enterprise Java applications or advancing their existing ones.

Source available recipe module

This guide uses org.openrewrite.recipe:rewrite-migrate-java, a Moderne source-available recipe module. Compiled binaries are only available to Moderne customers, hosted at the Code Genome Project. For non-commercial use you can compile and publish the recipe module locally to use the recipes.

Configuration

This recipe has no required configuration options. It can be activated by adding a dependency on `org.openrewrite.recipe:rewrite-migrate-java` in your build file or by running a shell command (in which case no build changes are needed):

OpenRewrite artifacts are distributed through the Code Genome Project repository (https://artifacts.codegenomeproject.org/maven), which requires authentication. Sign in to the Code Genome Project to create a download token, then in the snippets below replace USERNAME with the email or username you signed in with and TOKEN with that token. See the quickstart guide for details.

  1. Add the following to your build.gradle file:
    build.gradle
    plugins {
    id("org.openrewrite.rewrite") version("latest.release")
    }

    rewrite {
    activeRecipe("org.openrewrite.java.migrate.jakarta.JakartaEE10")
    }

    repositories {
    mavenCentral()
    maven {
    url = "https://artifacts.codegenomeproject.org/maven"
    credentials {
    username = "USERNAME"
    password = "TOKEN"
    }
    }
    }

    dependencies {
    rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.42.1")
    }
  2. Run gradle rewriteRun to run the recipe.

For the full list of changes this recipe will make, see the recipe reference page.

Once you've configured your project, you're ready to execute the migration by running mvn rewrite:run or gradlew rewriteRun. After running the migration you can inspect the results with git diff (or equivalent), manually fix anything that wasn't able to be migrated automatically, and commit the results.

Before and After

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>com.netflix.priam.defaultimpl.InjectedWebListener</listener-class>
</listener>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/REST/*</url-pattern>
</filter-mapping>

</web-app>
import javax.inject.Inject;
import javax.inject.Singleton;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import javax.servlet.ServletContextEvent;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.servlet.http.HttpUtils;

// ...

public class HttpHandlerWithServletSupport implements HttpHandler {
@Override
public javax.servlet.ServletOutputStream getOutputStream() throws IOException {
return servletOutputStream;
}
}

This recipe will also remove javax implementations from a build.gradle file such as:

dependencies {
implementation "javax.servlet:javax.servlet-api:4.0.1"
}

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.