Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet
Asked Answered
H

2

5

What could be causing this error?

    Caused by: jakarta.servlet.UnavailableException: Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet
        at org.eclipse.jetty.servlet.ServletHolder.checkServletType (ServletHolder.java:499)
        at org.eclipse.jetty.servlet.ServletHolder.doStart (ServletHolder.java:377)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:96)
        at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$2 (ServletHandler.java:699)
        at java.util.stream.SortedOps$SizedRefSortingSink.end (SortedOps.java:357)
        at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:485)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:474)
        at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining (StreamSpliterators.java:312)
        at java.util.stream.Streams$ConcatSpliterator.forEachRemaining (Streams.java:735)
        at java.util.stream.ReferencePipeline$Head.forEach (ReferencePipeline.java:658)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

I'm running the web app from mvn jetty:run plugin

Hadleigh answered 29/9, 2020 at 10:26 Comment(0)
R
10

jakarta.servlet.UnavailableException: Servlet class [...] is not a jakarta.servlet.Servlet

The jakarta.servlet.Servlet is part of Servlet API version 5.0 which in turn is part of Jakarta EE version 9. This can thus only mean that the servlet class specified in [...] is NOT compiled against Servlet API version 5.0, but against an older version.

You have 2 options:

  1. Upgrade the servlet class specified in [...] to a Servlet API version 5.0 compatible one.

  2. Or, downgrade the servlet container from Servlet API version 5.0 to a previous version, at least the one matching the target Servlet API version of the servlet class specified in [...].

The technical reason is that during the step from Java/Jakarta EE 8 to Jakarta EE 9 all javax.* packages have been renamed to jakarta.* packages. So there is no backwards compatibility anymore since Jakarta EE 9.

When we translate the above facts to your specific situation, your only option is to downgrade the Jetty servlet container to a Servlet 4.0 compatible version. This is because the 3rd party library "Restlet" has currently (Jul 2024) still no Servlet 5.0 compatible version available at all. According to Jetty's version table, Jetty 11.x is Jakarta EE 9 targeted, so you need Jetty version 10.x or older. In case you're using Tomcat, you need Tomcat version 9.x or older.

Alternatively, you can drop Restlet altogether and use Jersey instead. It has currently a Jakarta EE 9 compatible version available. Or when you're actually targeting a Jakarta EE server such as WildFly, GlassFish, Liberty, etc then simply use built-in Jakarta RESTful (JAX-RS) functionality instead without the need for any additional dependencies.

See also:

Ruffi answered 29/9, 2020 at 10:59 Comment(5)
Already have ` <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency>`Hadleigh
quarks, it doesn't work that way. The target runtime itself must actually also be that servlet API version. The provided entry in pom.xml doesn't magically change the target runtime to the expected version. You can still run it against Jetty 11.x and end up into the specified trouble. As explained in the answer, you need to physically downgrade Jetty to 10.x in order to comply the expectation as specified in pom.xml.Ruffi
Oh shoot, you're right. Apparently in my POM the ${jetty.version} was removed causing it to fetch the version 11, my bad.Hadleigh
Can happen to the best.Ruffi
you may be interested to give a comment on this #64119491 tooHadleigh
H
0

I was trying to run a Maven application inside a Wildfly server

I installed 20.0.1.Final, the last version before Jakarta

Harmonia answered 11/12, 2021 at 0:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.