Expand my Community achievements bar.

SOLVED

replacing javax.servlet with jakarta.servlet dependency for AEM Servlet

Avatar

Level 1

As javax.servlet dependency has been deprecated we are getting tidelift suggestions to upgrade to jakarta.servlet. However, when we update to that we are getting below error -

Error: /apps/runner/_work/jabcd/japp-name/core/pom.xml [0:0]: Class org.ab.web.appname.core.servlet.FetchPDF is not assignable to specified service jakarta.servlet.Servlet

 

Suggestions on this error asking again to revert back to javax.servlet. 

Just checking has anyone encountered this issue before? What solution has been implemented to address this. Pls share your experience. Thanks.

 

-Nilesh

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Currently the work started to allow the use of jakarta.servlet instead of javax.servlet, but I guess that it will take some time to get offically supported.

View solution in original post

5 Replies

Avatar

Community Advisor

 This issue commonly occurs when upgrading from javax.servlet to jakarta.servlet. The primary reason is that jakarta.servlet introduces breaking package changes, which require recompiling and updating dependencies accordingly. You can try below steps to resolve this issue:

1. If your project has dependencies that still rely on javax.servlet, they may not be compatible with jakarta.servlet.

  • Replace all javax.servlet dependencies with jakarta.servlet-compatible versions.
  • Run mvn dependency:tree to check if any transitive dependencies are still pulling in javax.servlet.tible with jakarta.servlet

2. Your FetchPDF class may still be compiled against javax.servlet.Servlet, causing class incompatibility.

  • Ensure your servlet class imports jakarta.servlet.* instead of javax.servlet.*.
  • Clean and rebuild your project (mvn clean install).

3. Some older servlet containers (e.g., Tomcat 9, Jetty 9) still use javax.servlet. Jakarta Servlet 5+ is only supported from Tomcat 10, Jetty 11, etc.

  • Upgrade your servlet container to Tomcat 10+ or Jetty 11+, which support jakarta.servlet.

4. If using Spring Boot, ensure you have updated dependencies properly:

  • Spring Boot 2.x still uses javax.servlet. To use jakarta.servlet, upgrade to Spring Boot 3.x.

Reference - https://foojay.io/today/migrating-from-java-ee-to-jakarta-ee-with-intellij-idea/ 

Regards,

Shiv Prakash

Avatar

Level 7

1. Ensure Compatibility: AEM uses javax.servlet and may not fully support jakarta.servlet yet, especially in older versions.
2. Revert to javax.servlet: If AEM doesn't support jakarta.servlet, revert to using javax.servlet in your pom.xml:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>

3. Update Servlets: If you're using jakarta.servlet, make sure your servlet code uses the correct import: 

import jakarta.servlet.Servlet;

4. Check AEM Version: If you're on a version that supports jakarta.servlet, update your servlets accordingly. If not, stick to javax.servlet.

Avatar

Level 1

Thanks Amit. I believe AEM does not support jakarta.servlet yet (until version 6.5) as jakarta API is not compatible with OSGI services, hance wanted to check if there has been any workaround to make it work. For now I'll keep using javax api until we have an update from Adobe side to use jakarta api with compatible AEM vesion. 

Avatar

Correct answer by
Employee Advisor

Currently the work started to allow the use of jakarta.servlet instead of javax.servlet, but I guess that it will take some time to get offically supported.

Avatar

Level 1

Thank you for the update. So we will continue using the javax.servlet until jakarta.servlet officially starts supporting it.