I'm getting this tomcat error " java.lang.ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer" when I run Tomcat using eclipse :
I see that eclipse does not include the jars into the (tomcat 7.0) WEB-INF/Lib folder, though I tried this :
Included the Maven dependencies in "Web Deployment Assembly" under Project properties. ( Maven downloaded the dependencies in the POM.xml , but these jars are not getting picked up by eclipse )
The POM.xml as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dcr.javacode.rest.jersey</groupId>
<artifactId>JAXRS-HelloJerseyExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
</project>
web.xml as follows :
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JAXRS-HelloJerseyExample</display-name>
<servlet>
<servlet-name>JerseyRESTService</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.dcr.javacode.rest.jersey</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyRESTService</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Couple things I see wrong.
<packaging>
element in the pom file. If this is to be deployed to a servlet container, then the package should bewar
. The default isjar
jersey-server
which doesn't have theServletContainer
. Instead usejersey-container-servlet
But...
The easiest way to get started with Jersey is to use a Maven archetype.
In Eclipse:
File
] → [New
] → [Other
]Maven
] → [Maven Project
] → Nextjersey-quickstart-webapp
. It might take a few moments to load all the archetypes. You can see the progress of the archetypes loading in a little progress bar at the very bottom right of the IDE. If you don't see the progress bar and there are no search results, then most likely you don't have the archetypes. In that case, follow the instructions in the first part of this answerorg.glassfish.jersey.archetypes
version. It should default to the latest version (at this time it's 2.17) → NextThat should get you a running Jersey starter app, that will run on Tomcat