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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

9

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 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:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Already have ` javax.servlet javax.servlet-api 4.0.1 provided ` – quarks Sep 29 '20 at 11:07
  • 2
    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. – BalusC Sep 29 '20 at 11:08
  • Oh shoot, you're right. Apparently in my POM the `${jetty.version}` was removed causing it to fetch the version 11, my bad. – quarks Sep 29 '20 at 11:12
  • 1
    Can happen to the best. – BalusC Sep 29 '20 at 11:37
  • you may be interested to give a comment on this https://stackoverflow.com/questions/64118991/transactional-objects-over-rmi too – quarks Sep 29 '20 at 11:49
0

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

I installed 20.0.1.Final, the last version before Jakarta

hestellezg
  • 3,309
  • 3
  • 33
  • 37