1

I am trying to create a simple webservice using jersey rest webservices. So I created a simple class that i called main :

@Path("/main")
public class main {
@GET
@Path (value="Stringtest")
@Produces(MediaType.APPLICATION_JSON)
public String Stringtest()
{
System.out.println("************");
return ("string");
}
}

And then I chaged web.xml ( my package's name is "test")

<?xml version="1.0" encoding="ASCII"?>
<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" version="3.0">
<display-name>rest</display-name>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param> 
<param-name>com.sun.jersey.config.property.packages</param-name> 
<param-value>test</param-value> 
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

it seems that there is something wrong in the web.xml because i get this error

Infos: Scanning for root resource and provider classes in the packages:
test
AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Infos: Root resource classes found:
class test.main
com.sun.jersey.api.core.ScanningResourceConfig init
Infos: No provider classes found.

Are there any suggestions to this issue? Please help!

4
  • 2
    This is perfectly legit. There is no error there. Class test.main is found without problems. You don't have provider classes, but this is not an error, just information. Commented May 22, 2014 at 11:23
  • 1
    But when i run the project I get "State HTTP 404- /New/" the requested resource is not available.
    – Sahar Ch.
    Commented May 22, 2014 at 11:27
  • 1
    Try /{yourContextRoot}/main/Stringtest instead of /New.
    – lefloh
    Commented May 22, 2014 at 12:03
  • I just tried it and got the same error : still not working :-(
    – Sahar Ch.
    Commented May 22, 2014 at 13:09

2 Answers 2

2

Maybe you have a problem in your tomcat configuration.Check this link http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

0
0

Seems to me that you are accessing the wrong url

Add "/" to your test class

@GET
@Path ("/Stringtest")
@Produces(MediaType.APPLICATION_JSON)
public String Stringtest()

Acess with this url: (your context)/rest/main/Stringtest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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