I believe you can make use of a migration tool.

from tomcat 9 to tomcat 10.0

Specification APIs

Apache Tomcat 10 supports the Jakarta Servlet 5.0, Jakarta Server Pages 3.0, Jakarta _expression_ Language 4.0, JakartaWebSocket 2.0 and Jakarta Authentication 2.0 specifications.

There is a significant breaking change between Tomcat 9.0.x and Tomcat 10.0.x. The Java package used by the specification APIs has changed fromjavax... to jakarta.... It will be necessary to recompile web applications against the new APIs.

Tomcat can convert an existing web application from Java EE 8 to Jakarta EE 9 at deployment time using the Apache Tomcat migration tool for Jakarta EE. To make use of the feature, the web application should be placed in the Host legacyAppBase folder (by default named webapps-javaee) and they will be converted to an equivalent Jakarta EE web application in the Host appBase folder (by default named webapps).

Alternately, the Apache Tomcat migration tool for Jakarta EE or any similar conversion tool can be used ahead of time to benefit from faster deployment time and more precise conversion configuration options.



On Nov 21, 2023, at 1:36 PM, Robert Turner <rtur...@e-djuster.ca> wrote:

Tomcat 10.x and higher require Jakarta namespaces versions of the Servlet
specifications.
Tomcat 9.x is the last Tomcat support javax.servlet namespaces.

Refer to the Which Version page for Tomcat for details:
https://tomcat.apache.org/whichversion.html

On Tue, Nov 21, 2023 at 3:30 PM Campbell, Lance <la...@illinois.edu> wrote:

I am migrating from Java 8 tomcat 9 to Java 11 tomcat 10.1 .

I am getting a cast class exception when trying to access my login
servlet. In my servlets I am using these packages:


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


 1.  Does either Java 11 or Tomcat 10.1 require that I use
Jakarta.servlet.* packages instead of javax.servlet.*?
 2.  If that is the case, then what is specifically requiring this? Is it
Java 11 or Tomcat 10.1 or both?

My servlet is getting this error:

21-Nov-2023 14:14:52.768 INFO [main]
org.apache.catalina.core.ApplicationContext.log Marking servlet
[LoginServlet] as unavailable
21-Nov-2023 14:14:52.769 SEVERE [main]
org.apache.catalina.core.StandardContext.loadOnStartup Servlet
[LoginServlet] in web application [] threw load() exception
       java.lang.ClassCastException: class xyz.servlet.LoginServlet
cannot be cast to class jakarta.servlet.Servlet
(xyz.servlet.LoginServlet is in unnamed module of loader
org.apache.catalina.loader.ParallelWebappClassLoader
@2ccca26f; jakarta.servlet.Servlet is in unnamed module of loader
java.net.URLClassLoader @63e2203c)

Thanks,

Lance

Reply via email to