eclipse - Java dynamic webserver - unable to read 'hello world' jersey resource -


im using jersey 2.0 , have installed jersey jar files eclipse using site

the issue having cannot load hello world project.

here project structure:

enter image description here

and here web.xml located in web-inf:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="webapp_id" version="3.1">   <display-name>com.vogella.web.filecounter2</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 rest service</servlet-name>     <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>      <!-- register resources , providers under com.vogella.jersey.first package. -->     <init-param>         <param-name>com.vogella.web.resources</param-name>         <param-value>com.vogella.web.filecounter2</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>jersey rest service</servlet-name>     <url-pattern>/rest/*</url-pattern>   </servlet-mapping> 

and here hello world class:

 package com.vogella.web.resources;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype;  //sets path base url + /hello @path("/hello") public class hello {      // method called if text_plain request     @get     @produces(mediatype.text_plain)     public string sayplaintexthello() {         return "hello jersey";     }      // method called if xml request     @get     @produces(mediatype.text_xml)     public string sayxmlhello() {         return "<?xml version=\"1.0\"?>" + "<hello> hello jersey" + "</hello>";     }      // method called if html request     @get     @produces(mediatype.text_html)     public string sayhtmlhello() {         return "<html> " + "<title>" + "hello jersey" + "</title>"                 + "<body><h1>" + "hello jersey" + "</body></h1>" + "</html> ";     }  } 

the issue having when run server says resource not found. here link:

http://localhost:8080/com.vogella.web.filecounter2/rest/hello 

update: here list of jar files have:

enter image description here

and here error when try view resource either in eclipse or on chrome:

enter image description here

the code in web.xml needs correction.

<init-param>      <param-name>com.vogella.web.resources</param-name>      <param-value>com.vogella.web.filecounter2</param-value>  </init-param> 

the param-name , param-value fields not correct. change param-name jersey.config.server.provider.packages , param-value com.vogella.web.resources.

the correction should

<init-param>     <param-name>jersey.config.server.provider.packages</param-name>     <param-value>com.vogella.web.resources</param-value> </init-param> 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -