[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?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

16 thoughts on “[Solved] java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer”

  1. i am getting below issue

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

    Can any one help me with this?

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.