问题
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
回答1:
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:
Upgrade the servlet class specified in
[...]
to a Servlet API version 5.0 compatible one.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 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.
Alternatively, you can drop Restlet altogether and use Jersey instead. It has currently a Jakarta EE 9 compatible version available.
See also:
- Jetty versions
- Getting java.lang.ClassNotFoundException: jakarta.servlet.Filter on Maven/Jersey web service while running on Tomcat 9
来源:https://stackoverflow.com/questions/64117697/servlet-class-org-restlet-ext-servlet-serverservlet-is-not-a-jakarta-servlet-ser