SOLVED: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

If you have start working on Jersey then you might face this issue while configuring it. This is the result of insufficient project dependencies on runtime. This issue is likely to be faced in tomcat server.

Random exceptions

Random exceptions

The error log will look like this.

SEVERE: Servlet /JerseyHelloWorld threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
	at org.apache.catalina.loader.WebappClassLoader.loadClass(
	at org.apache.catalina.loader.WebappClassLoader.loadClass(
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(
	at org.apache.catalina.core.StandardWrapper.loadServlet(
	at org.apache.catalina.core.StandardWrapper.load(
	at org.apache.catalina.core.StandardContext.loadOnStartup(
	at org.apache.catalina.core.StandardContext.startInternal(
	at org.apache.catalina.util.LifecycleBase.start(
	at org.apache.catalina.core.ContainerBase$
	at org.apache.catalina.core.ContainerBase$
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$ Source)
	at Source)

To solve this issue, correct the project dependencies in pom.xml like below. If you are not using maven for project dependencies, include the corresponding jar files in classpath.


This will solve the issue.

Happy Learning !!

20 thoughts on “SOLVED: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer”
  1. Working on REST webservice using Jersey implementation. Please help me to resolve this issue.
    Java -1.7
    Dynamic Web Module Project Facet – 2.4

    pom.xml: Repository for Maven



    2015-07-28 19:19:16.809:INFO:oejs.Server:jetty-8.1.16.v20140903
    2015-07-28 19:19:16.984:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{null,file:/Users/ctsuser/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/RESTfulExample/},/Users/ctsuser/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/RESTfulExample
    java.lang.IllegalStateException: Null contextPath
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(
    at org.eclipse.jetty.webapp.WebAppContext.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(
    at org.eclipse.jetty.server.Server.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.wst.server.preview.internal.PreviewStarter.main(
    2015-07-28 19:19:17.407:WARN:oejs.Holder:
    java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

  2. i want change my maven project into dynamic web project.I deleted pom.xml file and i took one new work space and i import the project. i getting following errors.i added all jar files required.
    Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener.
    Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory.

    1. I hope you have already added commons logging jars in project. If not then do so. java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory asking for it.

      If that doesn’t work the import commons logging jars as external jar libraries to the project.

      1. Already i have done all these thing then i came into public so give me some extra different situations you have faced and resolved.

        Actually i had deleted pom.xml file .with that file maven project worked peoperly. I downloaded according to that pom file and i added that jars in buildpath of eclipse. after that i got this type of error and it is not resolved.
        so basing on this situation give some ideas to resolve it.

        1. How to resolve this error?
          SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
          java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

        2. Your problem is straight forward. Commons logging is available in compile time, and NOT available in runtime. You can verify this by copying jar file in tomcat lib folder. If it works then make sure that generated war file contains this file in lib.

  3. I’m still facing the classNotFoundException, though i have all the required jars specified above exists in my project library.

    SEVERE: Servlet /SimpleRest threw load() exception
    java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
    at org.apache.catalina.loader.WebappClassLoader.loadClass(

    I’m using tomcat 7 + JDK 7 + REST 2.0 API

    Can you please advise me. Thanks

  4. This is really very helpful. It solved my errors. I’ve also started reading your other articles. They are very simple and straight forward.

    Thanks again!!!!

  5. It doesn’t solve the issue for me :(
    I tried everything I found on the internet, but it’s like none of them actually does anything.
    I still have tons of errors like:
    java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

      1. Thank you, Lokesh! I solved the problem in the meanwhile and I wanted to post it here for everyone. In my case, all I had to do (and it’s kinda funny) is restart my computer. Why? I’m guessing this could be a Netbeans bug – maybe it doesn’t close Tomcat even when you press stop? The point is, I added the dependencies like in your post and it still didn’t work, even after stopping and starting again both my web service and Tomcat. Then, the next day, without doing anything else but restarting my computer, everything was working well.

        1. Really weird, but thank you for updating your fix here. It might be helpful for other’s working on netbeans. [I am wondering if others facing similar issue would have to wait till next day to restart the computer.. :) just kidding.]

  6. Wow. Thanks a million. All the tutorials have older versions of jersey and none of them told me to use jersey-servlet. I fought with this for HOURS. thanks,

Note:- In comment box, please put your code inside [java] ... [/java] OR [xml] ... [/xml] tags otherwise it may not appear as intended.

Leave a Reply

Your email address will not be published. Required fields are marked *