Main Tutorials

NoClassDefFoundError: jakarta/servlet/ServletInputStream

Using Jersey 3x + Jetty to develop endpoints, but hits the following error during application startup.

Terminal

Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/servlet/ServletInputStream
  at org.glassfish.jersey.jetty.JettyHttpContainerProvider.createContainer(JettyHttpContainerProvider.java:43)
  at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:58)
  at org.glassfish.jersey.jetty.JettyHttpContainerFactory.createServer(JettyHttpContainerFactory.java:110)
  at com.mkyong.MainApp.startServer(MainApp.java:22)
  at com.mkyong.MainApp.main(MainApp.java:32)

Caused by: java.lang.ClassNotFoundException: jakarta.servlet.ServletInputStream
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
  ... 5 more

1. jakarta/servlet/* and Servlet API 5.0

Since Servlet API 5.0, the API moved from the package javax.servlet to jakarta.servlet.

Below is the short history of Servlet API

Servlet API Release Platform Note
Servlet 5.0 Jun 12, 2020 Jakarta EE 9 API moved from package javax.servlet to jakarta.servlet
Servlet 4.0.3 Aug 13, 2019 Jakarta EE 8 Renamed from "Java" trademark, API package still javax.servlet
Servlet 4.0 Sep 2017 Java EE 8 javax.servlet
Servlet 3.1 May 2013 Java EE 7 javax.servlet

2. Solution

Some libraries depend on the Servlet API 5.0, which can not found in the project dependency. We can fix it by including the following [email protected]:

pom.xml

  <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
      <version>5.0.0</version>
  </dependency>

3. References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Willow Rocha
10 months ago

Solved my problem, thanks!