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

I am trying to make a web service with Tomcat and Eclipse using the jersey library. This is my class of service:

package com.gontuseries.university; import javax.ws.rs.core.MediaType; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @Path("/university") public class UniversityRestWs { @GET @Produces(MediaType.TEXT_HTML) public String getHtmlUniversityInfo(){ return "<html><body>test</body></html>"; } @GET @Produces(MediaType.TEXT_PLAIN) public String getTextUniversityInfo(){ return "test"; } } 

And this is the web.xml file

  <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.gontuseries.university</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> 

When I test my service, I get java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer I loaded the jersey from https://jersey.java.net/download.html

Can someone help me? Thanks

+7
java eclipse tomcat jersey
source share
10 answers

For me, the problem was that there were no jars in the lib folder on the server. Make sure it has access to all the dependencies: project -> properties -> development assembly -> add -> java build path entries.

+12
source share

I had the same problem. We just need to use the path to create Eclipse. That will work.

Make sure that it has access to all the dependencies in: project -> properties -> build assembly -> add -> java build path entries -> maven dependency

I used only jersey bundle dependency

"addiction

  <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.17</version> 

addiction "

If you are using maven, the best few simple steps will work with your application

+9
source share

Man, I had the same problem. I solve id by adding jersey-servlet-1.18.jar to WEB-INF / lib. Then this folder looked like this:

.
Remember, add all these jars to the yout build path

+7
source share

Do you use Jersey 2.x? If so, the ServletContainer class has been moved to another package. This article has good information on how to change your web.xml when porting from Jersey 1.7 to 2.x: https://java.net/projects/jersey/lists/users/archive/2013-06/message/91 .

+6
source share

The class com.sun.jersey.spi.container.servlet.ServletContainer contained in "jersey-servlet.jar", so you should put it in WEB-INF / lib along with "jersey-server.jar".

+4
source share

I got the same error - "java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer" while trying to execute a quiet jersey web service in tomcat from eclipse.

The following steps helped me solve the problem:

  • Fix maven dependency to the correct version of dependent jars

      <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19</version> </dependency> 
  • Right click on eclipse project -> Maven -> Update Project

  • Verify that the eclipse properties assembly is configured correctly. Right click on the project - Properties -> assembly assembly -> Add -> Java assembly path entries -> maven dependency

+1
source share

If you are using the JERSEY-jaxrs-ri-2.9 version of zip, use the following in the WEB.XML file.

 <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> ...... </init-param> 
0
source share

I was getting this error in an Eclipse project that previously worked fine while working on Tomcat 7.0. In the end, I solved this by deleting the project from Tomcat and adding it back.

0
source share

The above solutions are correct, but even after making these changes, I got this error. So what I did was remove all the loaded Jersey cans and updated Project again with a new maven dependency and which resolved my problem.

0
source share

We get this error due to a build path error and deprecated dependency names. The oldest run from org.glassfish, not com.sun. After replacing with the latest dependencies for 2.0,. You must add a "Runtime Server" in the build path.

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

To resolve a class exception not found, follow these steps.

Right click on the project β†’ Build Path β†’ Build Path β†’ Add Library β†’ Server Runtime β†’ Apache Tomcat v7.0

Thanks, Sachin GN

-one
source share

All Articles