I am a newby in web development and I am struggling to create a simple rest web service using jersey, packed as an independent war file, to be deployed on tomcat 7.
I have followed this tutorial in order to create simple hello world restful web service. I have used intelij in order to create the war file (both war file and exploded version of it) and deployed them on the tomcat\webapps folder.
When starting up the tomcat, I fail to access the url (http://localhost:8080/rest/hello
) - getting 404.
Looking at the tomcat's logs, I can't find any exception or error, other then these next set of lines:
INFO: Scanning for root resource and provider classes in the packages:
sample
εαΘ 30, 2013 11:24:38 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class sample.Hello
εαΘ 30, 2013 11:24:38 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
I have searched it a lot and tried to follow all solutions for this error but nothing worked.
I have the feeling that I missing something very basic, due to my newbi'ness. Any ideas what to search ? what am I missing ? it's a simple hello world app and I am exahuster and frustrated...
Java class
package sample;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("hello")
public class Hello {
// This method is called if TEXT_PLAIN is requested
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHelloInPlainText() {
return "Hello world!";
}
// This method is called if HTML is requested
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHelloInHtml() {
return "<html> " + "<title>" + "Hello world!" + "</title>"
+ "<body><h1>" + "Hello world!" + "</body></h1>" + "</html> ";
}
}
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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>rest</display-name>
<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</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>