You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Campbell, Lance" <la...@illinois.edu> on 2023/11/21 20:29:42 UTC

Issue Migrating servlets to 10.1

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

Re: Issue Migrating servlets to 10.1

Posted by Paul Leo <pl...@gmail.com>.
I believe you can make use of a migration tool.

  

[| [Apache Tomcat® - Migration Guide - Tomcat
10.0.x](https://tomcat.apache.org/migration-10.html)[tomcat.apache.org](https://tomcat.apache.org/migration-10.html)|
[![favicon.ico](cid:7D80E2AB-A8E4-4BBC-B886-E03A802494A9)](https://tomcat.apache.org/migration-10.html)  
---|---  
](https://tomcat.apache.org/migration-10.html)

  

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](https://cwiki.apache.org/confluence/display/TOMCAT/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](https://tomcat.apache.org/download-migration.cgi) 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 <rt...@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  
>
>

>>  
>


Re: Issue Migrating servlets to 10.1

Posted by Eduardo Guadalupe <ed...@gmail.com>.
Many libraries that require JDK 11 or 17 are very likely to have migrated
to Jakarta(if they used javax)

On Tue, Nov 21, 2023, 14:53 Robert Turner <rt...@e-djuster.ca> wrote:

> I don't think there is an upper limit. I know 17 works for us, but your
> mileage may vary depending on your app libraries, etc.
>
>
> On Tue, Nov 21, 2023, 15:49 Campbell, Lance <la...@illinois.edu> wrote:
>
> > Thanks so much.
> > One last question. If I want to use javax.serlet.* then what is the
> > highest version of Java I should use?
> >
> > Thanks,
> >
> > Lance
> >
> > -----Original Message-----
> > From: Robert Turner <rt...@e-djuster.ca>
> > Sent: Tuesday, November 21, 2023 2:36 PM
> > To: Tomcat Users List <us...@tomcat.apache.org>
> > Subject: Re: Issue Migrating servlets to 10.1
> >
> > 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://urldefense.com/v3/__https://tomcat.apache.org/whichversion.html__;!!DZ3fjg!4VB2wQDqugXc0S2euhB5gcgb0Cu6xk-8SLRK_GwqXTxu2U6M3PLo_zrv8d_LmTAOeY0pUCw2GMYHX0pcXv1cMQ$
> >
> > 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
> > >
> >
>

Re: Issue Migrating servlets to 10.1

Posted by Robert Turner <rt...@e-djuster.ca>.
I don't think there is an upper limit. I know 17 works for us, but your
mileage may vary depending on your app libraries, etc.


On Tue, Nov 21, 2023, 15:49 Campbell, Lance <la...@illinois.edu> wrote:

> Thanks so much.
> One last question. If I want to use javax.serlet.* then what is the
> highest version of Java I should use?
>
> Thanks,
>
> Lance
>
> -----Original Message-----
> From: Robert Turner <rt...@e-djuster.ca>
> Sent: Tuesday, November 21, 2023 2:36 PM
> To: Tomcat Users List <us...@tomcat.apache.org>
> Subject: Re: Issue Migrating servlets to 10.1
>
> 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://urldefense.com/v3/__https://tomcat.apache.org/whichversion.html__;!!DZ3fjg!4VB2wQDqugXc0S2euhB5gcgb0Cu6xk-8SLRK_GwqXTxu2U6M3PLo_zrv8d_LmTAOeY0pUCw2GMYHX0pcXv1cMQ$
>
> 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
> >
>

RE: Issue Migrating servlets to 10.1

Posted by "Campbell, Lance" <la...@illinois.edu>.
Thanks so much.
One last question. If I want to use javax.serlet.* then what is the highest version of Java I should use? 

Thanks,

Lance

-----Original Message-----
From: Robert Turner <rt...@e-djuster.ca> 
Sent: Tuesday, November 21, 2023 2:36 PM
To: Tomcat Users List <us...@tomcat.apache.org>
Subject: Re: Issue Migrating servlets to 10.1

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://urldefense.com/v3/__https://tomcat.apache.org/whichversion.html__;!!DZ3fjg!4VB2wQDqugXc0S2euhB5gcgb0Cu6xk-8SLRK_GwqXTxu2U6M3PLo_zrv8d_LmTAOeY0pUCw2GMYHX0pcXv1cMQ$ 

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
>

Re: Issue Migrating servlets to 10.1

Posted by Robert Turner <rt...@e-djuster.ca>.
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
>