Java – HTTP status when testing restful webservice404 using Jersey
I've been trying to develop and deploy a quiet web service using Jersey I've been following docs oracle. COM and other various sources, but obtained HTTP status 404 when testing the service
Here is my 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>Hello World</display-name> <servlet> <servlet-name>Hello</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.rest.jersey.test</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/resources/*</url-pattern> </servlet-mapping> </web-app>
This is my service
package com.rest.jersey.test; import javax.ws.rs.Path; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/hello") public class HelloWorld { @GET @Produces(MediaType.TEXT_PLAIN) public String response(){ return "Hello World!"; } }
When I try to click on the URL
http://localhost:8080/TestRestWithJersey/resources/hello
It gives HTTP status 404 error Please help me solve this problem
I just checked the eclipse log file, and it didn't say anything except this:
I don't understand the news. Can you help me?
In addition, the Tomcat log when hitting the URL says
SEVERE: Error loading WebappClassLoader context: /TestRestWithJersey delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@5362ab com.sun.jersey.spi.container.servlet.ServletContainer java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
I added Jersey server Jar and jsr-311 jar
I've tried a single jersey bundle before jar
The problem remains
Any help is appreciated
Solution
If you want to deploy an application using a servlet container, you also need to add the Jersey servlet (see User Guide) module as a dependency of the project If you're using maven, simply say it
<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.15</version> </dependency>
Enter your POM XML file
If you want to use Jersey bundle, please make sure that there is ASM on your classpath, because package scanning (triggered by com.sun.jersey.config.property.packages init param in web.xml) requires this library to run normally