org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
The problem:
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
indicates that you try to use the Jersey 2.x servlet, but you are supplying the Jersey 1.x libs.
For Jersey 1.x you have to do it like this:
<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>sample.hello.resources</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>
For more information check the Jersey 1.x documentation.
If you instead want to use Jersey 2.x then you'll have to supply the Jersey 2.x libs. In a maven based project you can use the following:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.xx</version>
</dependency>
<!-- if you are using Jersey client specific features without the server side -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.xx</version>
</dependency>
For Jersey 2.x you don't need to setup anything in your web.xml
, it is sufficient to supply a class similar to this:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("rest")
public class ApplicationConfig extends Application {
}
For more information, check the Jersey documentation.
See also:
- java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
- Jersey Services with Tomcat and Eclipse
- ClassNotFoundException when starting tomcat
ClassNotFoundException: org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer when deploy war in WebLogic
I finally get the solution, as M. Deinum comments, the problem was the WebLogic packages, but in my case, I also have to add
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
<wls:package-name>com.google.common.*</wls:package-name>
</wls:prefer-application-packages>*
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
Wait, you said you have a Jersey library called jersey
, did you create a User Library
and name it jersey
? If so, try to copy your jersey jar files into WebContent -> WEB-INF -> lib.
ClassNotFoundException on ServletContainer when configuring Jersey in Intellij
I found the anwser with the help of Eugen Covaci.
In the Intellij project settings there is a tab called problems. When clicking solve on the problems listed there it started working again.
Another issue was that the jar files were located in web/WEB_INF/libs/api instead of the correct folder (web/WEB_INF/lib)
Related Topics
Jdbc Connection to Mssql Server in Windows Authentication Mode
How to Change the Arrow Style in a Jcombobox
Why Main() Method Is Needed in Java Main Class
Calling Superclass from a Subclass Constructor in Java
How to Save Preference User Settings in Java
Can't Cast to to Unspecific Nested Type with Generics
How to Output Two Columns to the Console in Java
How to Handle Precision Error with Float in Java
Spring Qualifier and Property Placeholder
How to Convert a 1D Array to 2D Array
Create a Jtds Connection String
Can't Transparent and Undecorated Jframe in Jdk7 When Enabling Nimbus