[java] org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException

I have been getting a ClassNotFoundException with org.glassfish.jersey.servlet.ServletContainer but it peculiarly started last night when I tried to start/re-start my Tomcat server (v7) with Eclipse Juno.

Not sure what is going on. What's bizarre is that it just started happening last night while it was working perfectly well before that.

Here is the stacktrace:

Feb 25, 2014 11:11:19 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet com.att.ucomm.admin.UCommAdminFunctions as unavailable
Feb 25, 2014 11:11:19 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /UCommAdminFunctions threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1671)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118    )
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4762)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5045)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3670)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:424)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1207)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1393)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1403)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1403)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1382)
at java.lang.Thread.run(Unknown Source)

Feb 25, 2014 11:11:19 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/UCommAdminFunctions] is completed
Feb 25, 2014 11:13:33 AM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet com.att.ucomm.admin.UCommAdminFunctions is currently unavailable

Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>
    <servlet-name>com.att.ucomm.admin.UCommAdminFunctions</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <!-- Register JAX-RS Application, if needed. -->
    <init-param>
        <param-name>com.att.ucomm.admin.UCommAdminFunctions</param-name>
        <param-value>my.package.MyApplication</param-value>
    </init-param>

    <!-- Register resources and providers under my.package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.att.ucomm.admin</param-value>
    </init-param>

    <!-- Register my custom provider (not needed if it's in my.package) AND LoggingFilter. -->
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>com.att.ucomm.admin.SecurityRequestFilter;org.glassfish.jersey.filter.LoggingFilter</param-value>
    </init-param>

    <!-- Enable Tracing support. -->
    <init-param>
        <param-name>jersey.config.server.tracing</param-name>
        <param-value>ALL</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>com.att.ucomm.admin.UCommAdminFunctions</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

I made sure that the jar files for jersey were still there in WEB-INF/lib:

WEB-INF/lib with jersey jars

This question is related to java tomcat jersey glassfish classnotfoundexception

The answer is


Suppose you are usin Jersey 2.25.1, this worked for me - I am using Apache Tomcat web container:

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.25.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.25.1</version>
    </dependency>

NB: Replace version with the version you are using


It's an eclipse setup issue, not a Jersey issue.

From this thread ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

Right click your eclipse project Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Gradle Dependencies -> Finish.

So Eclipse wasn't using the Gradle dependencies when Apache was starting .


I had the same problem with eclipse, the WA solution was to copy the libs to WEB-INF/lib


If you not use maven, try to put your jars to WEB-INF/lib, it worked for me.


If you are using Jersey 2.x use following dependency:

<dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-servlet-core</artifactId>
   <version>2.XX</version>
</dependency>  

Where XX could be any particular version you look for. Jersey Containers.


The jersey-container-servlet actually uses the jersey-container-servlet-core dependency. But if you use maven, that does not really matter. If you just define the jersey-container-servlet usage, it will automatically download the dependency as well.

But for those who add jar files to their project manually (i.e. without maven) It is important to know that you actually need both jar files. The org.glassfish.jersey.servlet.ServletContainer class is actually part of the core dependency.


I agree with the accepted answer. But for me, the issue was not that, instead I had to modify my Servlet-Class name from:-

<servlet-class>org.glassfish.jersey.servlet.ServletContainer.class</servlet-class> 

To:

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

So, removing .class worked fine in my case. Hope it will help somebody!


Below code work for me in web.xml file

<servlet>
    <servlet-name>WebService</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.example.demo.webservice</param-value>
        //Package
    </init-param>
    <init-param>
        <param-name>unit:WidgetPU</param-name>
        <param-value>persistence/widget</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>WebService</servlet-name>
    <url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to tomcat

Jersey stopped working with InjectionManagerFactory not found The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat Spring boot: Unable to start embedded Tomcat servlet container Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Kill tomcat service running on any port, Windows Tomcat 8 is not able to handle get request with '|' in query parameters? 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE 403 Access Denied on Tomcat 8 Manager App without prompting for user/password Difference between Xms and Xmx and XX:MaxPermSize

Examples related to jersey

How to download a file using a Java REST service and a data stream File upload along with other object in Jersey restful web service MessageBodyWriter not found for media type=application/json org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException How to add Headers on RESTful call using Jersey Client API java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer Dependency injection with Jersey 2.0 How to send and receive JSON data from a restful webservice using Jersey API Jersey client: How to add a list as query parameter @POST in RESTful web service

Examples related to glassfish

Cannot start GlassFish 4.1 from within Netbeans 8.0.1 Service area How to configure Glassfish Server in Eclipse manually org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException Location of GlassFish Server Logs How do I specify the JDK for a GlassFish domain? How to return a PNG image from Jersey REST service method to the browser Could not open ServletContext resource What is the difference between Tomcat, JBoss and Glassfish? Address already in use: JVM_Bind What does 'URI has an authority component' mean?

Examples related to classnotfoundexception

A child container failed during start java.util.concurrent.ExecutionException org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException How do I resolve ClassNotFoundException? HTTP Status 500 - Error instantiating servlet class pkg.coreServlet oracle.jdbc.driver.OracleDriver ClassNotFoundException java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...? JUNIT Test class in Eclipse - java.lang.ClassNotFoundException java.lang.ClassNotFoundException on working app