Note that there are some explanatory texts on larger screens.

plurals
  1. POJersey Tutorials from Basics
    primarykey
    data
    text
    <p>I am using Jersey 1.8 and the tutorials that I am referring are quiet old. Nothing works. I am referring to the tutorial given <a href="http://www.vogella.de/articles/REST/article.html" rel="nofollow">here</a> </p> <p>And get a class not found exception. as per the tutorial I made my Java Class as well as configured my web.xml. It shows me an exception and I am not getting a way to fix this. I would like to have a complete up to date tutorial for Jersey implementation. And if something is better than Jersey for REST implementation please suggest. I have rescently started with REST based web services and would appreciate if you can suggest me where to start from(I am only interested in REST). Below is the code that I wrote and compiled using eclipse.</p> <p>Hello.java</p> <pre><code>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 prints the Plain Text @GET @Produces(MediaType.TEXT_PLAIN) public String sayPlainTextHello() { return "Hello Jersey"; } //This is the XML request output @GET @Produces(MediaType.TEXT_XML) public String sayXMLHello() { return "&lt;?xml version=\"1.0\"?&gt;" + "&lt;hello&gt; Hello Jersey" + "&lt;/hello&gt;"; } //This result is produced if HTML is requested @GET @Produces(MediaType.TEXT_HTML) public String sayHTMLHello() { return "&lt;html&gt; " + "&lt;title&gt;" + "Hello Jersey" + "&lt;/title&gt;" + "&lt;body&gt;&lt;h1&gt;" + "Hello Jersey" + "&lt;/body&gt;&lt;/h1&gt;" + "&lt;/html&gt; "; } } </code></pre> <p>web.xml is as follows</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;display-name&gt;RESTFullApp&lt;/display-name&gt; &lt;servlet&gt; &lt;servlet-name&gt;JerseyRESTService&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer;&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;RESTFullApp&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;JerseyRESTService&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;!-- &lt;welcome-file-list&gt;--&gt; &lt;!-- &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;--&gt; &lt;!-- &lt;/welcome-file-list&gt;--&gt; &lt;/web-app&gt; </code></pre> <p>Noe the error I get while I try to run is </p> <pre><code>exception javax.servlet.ServletException: Servlet.init() for servlet JerseyRESTService threw exception org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Unknown Source) root cause com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes. com.sun.jersey.server.impl.application.RootResourceUriRules.&lt;init&gt;(RootResourceUriRules.java:99) com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298) com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771) com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766) com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488) com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318) com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609) com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) javax.servlet.GenericServlet.init(GenericServlet.java:212) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) java.lang.Thread.run(Unknown Source) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload