Jersey Maven configuration

vlio20

I am trying to setup a Jersey RESTful service, the problem is that I am getting the following error when trying to do GET request to the following API: http://localhost:8080/GroupAppServer/api/status:

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

Here is my web.xml file:

<?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"
    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>GroupAppServer</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>jersey-servlet</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>GroupAppServer</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jersey-servlet</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>
</web-app>

under src I have a package called "com.groupappserver.api" which holds my Status class. Here is the code:

package com.groupappserver.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.groupservice.utils.Response;

@Path("/status")
public class Status
{
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getStatus() 
    {
        return new Response();
    }

}

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>GroupAppServer</groupId>
    <artifactId>GroupAppServer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
        </dependency>

    </dependencies>
</project>

Any ideas why I am getting this error? and how can I fix this?

Konstantin V. Salikhov

Jersey servlet in your web.xml is misconfigured.

This servlet parameter should contain valid package name of your JAX-RS resource classes package:

   <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>GroupAppServer</param-value>
    </init-param>

In your case the package name should be com.groupappserver.api and not the value GroupAppServer you've specified.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jersey Maven configuration

From Dev

Jersey + Swagger + Swagger-UI + Maven configuration

From Dev

Jersey 2 Swagger configuration

From Dev

Jersey 2 client with maven

From Dev

Running Jersey examples with Maven

From Dev

Maven Configuration

From Dev

Jersey problems with Maven - Shade Plugin

From Dev

error with a jersey restful maven project

From Dev

Jersey Maven quickstart archetype in Eclipse

From Dev

error with a jersey restful maven project

From Dev

Integrating Jersey 2 and Spring with Java Based Configuration

From Dev

Jersey 2.1 JsonMoxy configuration in web.xml

From Dev

Application context configuration for json parsing in jersey

From Dev

How to integrate Swagger with Maven + Java + Jersey +Tomcat

From Dev

Maven dependency for testing using Jersey Test Framework

From Dev

Jersey-Spring3 maven dependency issue

From Dev

Maven build error with Jersey test framework

From Dev

Maven dependencies for REST API - Jersey - Glassfish or not?

From Dev

Running a maven jersey server from the command line

From Dev

AngularJs integration with Eclipse over Maven & Jersey

From Dev

REST web application in Maven using Jersey

From Dev

Multiple servlets on jersey (no spring nor maven)

From Dev

Execution VS Configuration in Maven

From Dev

Maven Java EE Configuration

From Dev

maven bundle plugin configuration

From Dev

Maven version control configuration

From Dev

Maven Report Configuration vs Build Configuration

From Dev

Spring-boot with maven configuration

From Dev

Maven Super POM & Plugin Configuration