HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Jersey / ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

[Solved] java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

We can face this exception if we are setting up jersey 2 project first time in eclipse using the Maven plugin.

The error message is simple enough to identify the root cause that the Jersey libraries are not in classpath.

The Error

The exception will look like this.

SEVERE: Servlet /JerseyDemos threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1137)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1081)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Solution – Add Jersey Library in Deployment Assembly

Open your project’s deployment assembly configuration.

Eclipse Deployment Assembly
Eclipse Deployment Assembly

Add Build path jar files in assembly so that they can be added to lib folder in the final .war file.

Deployment Assembly - Add Build Path Entries
Deployment Assembly – Add Build Path Entries

The updated assembly will look like this.

Deployment Assembly - Updated
Deployment Assembly – Updated

Now when you again run the project after building it, this will run fine and will be able to find org.glassfish.jersey.servlet.ServletContainer class.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. raju

    September 24, 2019

    Great, Its working for me. thanks

  2. Aidar

    March 30, 2019

    how to fix this on Intellij IDEA

  3. sushma

    January 21, 2019

    i am getting below issue

    org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: com/sun/jna/Pointer.

    Can any one help me with this?

    • Sunil sharma

      January 10, 2020

      Please check with the servlet-name name and param-name in web.xml once.

  4. Pavan Segalla

    July 31, 2018

    After 3 days finally, I was able to fix the issue with the help of this blog. Thanks a lot

  5. sandeep

    March 4, 2018

    Thanks a lot…

  6. ranjit

    February 9, 2018

    worked perfectly.

  7. Neha

    January 31, 2018

    In my project maven dependencies are already added but still I am getting the issue .please help me in resolving this.

    • Paulo

      February 27, 2020

      Do you remenber how you solved it?

  8. Sangeetha

    November 9, 2017

    After wasting many hours in fixing this issue, finally I found this blog. Issue resolved. Thanks a lot.

  9. Monika

    August 30, 2017

    Hi Lokesh, after clicking on next Java Build Path entries, there is nothing available and I am stuck there. Please do help.

    • Lokesh Gupta

      August 30, 2017

      Yours is maven project??

  10. YassmeenSayed

    August 29, 2016

    thanks a lot , this saved my sanity.

  11. Atula

    August 3, 2016

    perfectly worked, thanks a lot, you help me save many hours 🙂

  12. Sandip

    March 25, 2016

    Thanks a lot trying for a day .Now working perfectly.

  13. Sandeep

    January 20, 2016

    Thanks a lot. Had been trying to solve this problem for half a day. Perfectly worked.

Comments are closed on this article!

Search Tutorials

Jersey Tutorial

  • Jersey – Hello World
  • Jersey2 – Hello World
  • Jersey – quickstart-archetype
  • Jersey – Custom Logging
  • Jersey – Set Cookie
  • Jersey – File Download
  • Jersey – File Upload
  • Jersey – Multi-File Upload
  • Jersey – Exception Handling
  • Jersey – MOXy JSON
  • Jersey – JSONP
  • Jersey – Google Gson
  • Jersey – Security

Jersey Client

  • Jersey Client – Access REST APIs
  • Jersey Client – Authentication
  • Jersey Client – Set Cookie

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)