I'm creating a web application using Java AngularJS and Mysql but I when I run it using apache server I get this error :

GRAVE: Servlet [jersey-serlvet] in web application [/helloWorld] threw load() exception java.lang.ClassNotFoundException: 
com.sun.jersey.spi.container.servlet.ServletContainer

here is my pom.xml :

<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>helloWorld</groupId>
<artifactId>helloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ngdemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>

    <!-- Le connecteur de MYSQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
    </dependency>

    <!-- javax: XML binding -->
    <dependency>
        <groupId>javax.xml</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.1</version>
    </dependency>

    <!-- RESTful web service: Jersey -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.17.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.17.1</version>
    </dependency>

    <!-- Unit testing -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

</dependencies>
<build>
    <finalName>helloWorld</finalName>
</build>

and here is my web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
    <display-name>Restful Web Application</display-name>
    <servlet>
        <servlet-name>jersey-serlvet</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>ngdemo.rest</param-value>
        </init-param>

        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>
upvote
  flag
Add jersey bundle jar.Are you using eclipse – Raja Ramachandran

1 Answers 11

I don't think, you need below to include, as you have already included jersey-server. Please remove them and redeploy application.

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.17.1</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.17.1</version>
</dependency>

Also, please note that, you need to include same library at runtime, since, you are getting this exception at runtime.

upvote
  flag
doesn't resolve my problem – A.Aou
upvote
  flag
@A.Aou You need to keep only jersey-server and remove all. – Ravi
upvote
  flag
@A.Aou if your problem was resolved then read this meta.stackexchange.com/a/5235 – Ravi
upvote
  flag
how to include it – A.Aou
upvote
  flag
@A.Aou What do you mean by how to include it. It should be deployed at server. – Ravi
upvote
  flag
I deployed it but that doesn't helped me – A.Aou
upvote
  flag
@A.Aou then you aren't deploying the correct one. What is the jar, you have deployed ? – Ravi
upvote
  flag
I found a solution thank you for your help – A.Aou
upvote
  flag
@A.Aou What did you do ? if it was something different, which I suggested, then you need to post that answer else you are supposed to accept my answer – Ravi
upvote
  flag
@A.Aou please read this meta.stackexchange.com/a/5235 – Ravi

Not the answer you're looking for? Browse other questions tagged or ask your own question.