Java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

I have been trying to create a simple hello world application within two days using the google + google mechanism. For a simple AppEngine project, I followed these tutorials and both work great https://developers.google.com/appengine/docs/java/gettingstarted/creating https://developers.google.com/appengine/docs/java / webtoolsplatform

But now I'm trying to add a jersey and follow this tutorial http://www.vogella.com/articles/REST/article.html .

But the server keeps giving me

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

when i add these lines to web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>TestServer</display-name> <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.test.myproject</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> 

I downloaded the JAX-RS 2.1 RI bundle Jersey from here and added all the jar files to the WEB-INF/lib folder as described in the tutorial. And even after two days nothing works. I searched Google several times, and apparently the people who use Maven solved it somehow, but I don’t use Maven and not the guy who wrote this tutorial.

Just to check if even com.sun.jersey.spi.container.servlet.ServletContainer exists in the imported Jersey jars , I tried to just write this full name in Java and let the intellisense names end, but I could not get intellisense after com.sun.je , so my last assumption is that in the latest version of Jersey some sort of package permutation is built, and the jersey no longer inside com.sun . I am exhausted and I will be grateful for any help.

+73
eclipse java-ee google-app-engine jersey
Aug 6 '13 at 17:02
source share
16 answers

You downloaded Jersey 2 (which is RI JAX-RS 2). The tutorial that you mean is using Jersey 1. Downloading Jersey 1.17.1 from ( here ) should be enough for you.

Jersey 1 uses com.sun.jersey and Jersey 2 uses org.glassfish.jersey , hence the exception.

Also note that also init-param starting with com.sun.jersey will not be recognized by Jersey 2.

Edit

Registering Resources and Suppliers in Jersey 2 provides additional information on how to register classes / instances in Jersey 2.

+136
Aug 07 '13 at 9:40 on
source share

If you are using jersey 2.x, you need a different configuration in web.xml, since the servlet class is a change. you can update your web.xml with the following configuration.

  <servlet> <servlet-name>myrest</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>your.package.path</param-value> </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>myrest</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> 
+27
Dec 05 '13 at
source share

Add this to pom

 <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.17.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.17.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.17.1</version> </dependency> 
+19
Oct 31 '13 at 18:24
source share

This is an eclipse installation issue, not a Jersey issue.

From this topic ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

Right-click the eclipse project project β†’ Build Deployment β†’ Add β†’ Java Build Path Entries β†’ Gradle Dependencies β†’ Finish.

So, Eclipse did not use Gradle dependencies when starting Apache.

+4
Aug 4 '16 at 18:58
source share

try the following:

org.glassfish.jersey.servlet.ServletContainer

in the servlet class

+3
Apr 01 '14 at 22:04
source share

I had the same problem as you, although I went for a different guide: http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/

The strange part is that in this tutorial that I used, I should not have compatibility issues between versions (1.x versus 2.x), because according to the tutorial you use jersey 1.8.x on pom.xml and in web.xml you are referring to the class ( com.sun.jersey.spi.container.servlet.ServletContainer ), as indicated earlier in version 1.x. Therefore, I can assume that this should work.

My guess is that I am using JDK 1.7, this class no longer exists.




After I tried to resolve the answers before mine did not help, I made changes to pom.xml and the web.xml error changed to: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

What must have existed!

As a result of this error, I found a "new" solution: http://marek.potociar.net/2013/06/13/jax-rs-2-0-and-jersey-2-0-released/

With Maven (archetypes), create a knitwear project, like this:

 mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.0 

And it worked for me! :)

+2
Aug 27 '14 at 9:41
source share

I also ran into a similar problem. Fixed the issue by going through the tutorial in the steps of the link below.

http://examples.javacodegeeks.com/enterprise-java/rest/jersey/jersey-hello-world-example/

  • The main thing to note is that the jersey libraries must be correctly placed in the TOMCAT WEB-INF / lib folder. This is done automatically using the Eclipse settings specified in the link above. It will create a WAR file with dependent JAR files. In addition, you will have problems with ClassNotFound Exception.

Apache-7.0.56-Tomcat-Windows-x64 \ Apache -tomcat-7.0.56 \ WebApps \ JerseyJSONExample \ WEB-INF \ Lib

"11/23/2014 12:06 a.m. 130 458 jersey-client-1.9.jar

11/23/2014 12:06 AM 458 739 jersey-core-1.9.jar

11/23/2014 12:06 AM 147,952 jersey-json-1.9.jar

11/23/2014 12:06 713 089 jersey-server-1.9.jar "4 files 1,450,238 bytes

  • The second tutorial explains how to create a web service that produces and consumes JSON output.

http://examples.javacodegeeks.com/enterprise-java/rest/jersey/json-example-with-jersey-jackson/

Both links gave a good idea of ​​how everything works and saves a lot of time.

+2
Nov 22 '14 at 19:49
source share

We get this error due to a build path error. You must add the Runtime Server libraries 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 project --> Build Path --> Java Build Path --> Add Library --> Server Runtime --> Apache Tomcat v7.0

+1
Aug 07
source share

Today I faced the same error, although I used Jersey 1.x and had the right jars in my class. For those who would like to follow the vogella tutorial in a letter and use 1.x cans, you need to add the jersey libraries to the WEB-INF / lib folder. This will definitely solve the problem.

0
Jul 06
source share

you need to add jersey-bundle-1.17.1.jar to the project lib

<servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <!-- <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> --> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <!-- <param-name>jersey.config.server.provider.packages</param-name> --> <param-value>package.package.test</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>

0
Aug 23 '14 at 6:48
source share

You should replace in your web.xml:

 <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.test.myproject</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 

for this:

 <servlet> <servlet-name>Jersey REST Service</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.test.myproject</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 

this Jersey 2.x uses org.glassfish.jersey packages instead of com.sun.jersey (which is used by Jersey 1.x) and therefore an exception. Please note that also init-param starting with com.sun.jersey will not be recognized by Jersey 2.x after upgrading to JAX-RS 2.0 and Jersey 2.x

If you use maven at any time, your pom.xml will be as follows:

 <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.X</version> </dependency> 

replace 2.X for your version of desire, for example. 2.15

0
Jan 21 '15 at 22:31
source share

A simple workaround is to check for dependencies or libs in the eclipse.probably deployment assembly, if you use tomcat, the server may not have defined the libraries we are using. in this case, specify this explicitly in the deployment assembly.

0
Sep 15 '15 at 12:06
source share

Returning to the original problem - java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

As rightly stated above, in JAX 2.x, the ServletContainer class was moved to the package org.glassfish.jersey.servlet.ServletContainer. Associated jar of jersey-container-servlet-core.jar that comes bundled with jaxrs-ri-2.2.1.zip

JAX RS can be developed without mvn, manually copying all the banks contained in the zip file jaxrs-ri-2.2.1.zip (i used this version will work with any version 2.x) in the WEB-INF / lib folder. Copying libs to the right folder makes them available at run time.

This is necessary if you are using eclipse to create and deploy your project.

0
Sep 17 '15 at 19:14
source share

In the pom.xml file we need to add

 <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.8</version> </dependency> 
0
Aug 31 '17 at 12:05
source share

The same error and 2 hours spent debugging and trying all the parameters. I did not use Maven / POM, so I could not use this solution given by few.

Finally, this allowed the following: Adding banners directly to the tomcat / lib folder (NOT WEB-INF \ lib) and restarting tomcat.

0
Dec 13 '17 at 0:24
source share

If someone is trying to create a global welcome application using Jersey, I think one of the easiest ways is to follow the Jersey documentation.

https://jersey.imtqy.com/download.html

If you are already using maven, it only takes a few minutes to get the result.

I used below.

 mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.26 
0
Dec 19 '17 at 2:26
source share



All Articles