Jersey is a JAX-RS framework for J2EE.

First  you should download libraries

https://jersey.github.io/download.html

Unzip the zip file and copy the jar files in the following folders into WEB-INF/lib

  • \jaxrs-ri-2.17\jaxrs-ri\api
  • \jaxrs-ri-2.17\jaxrs-ri\ext
  • \jaxrs-ri-2.17\jaxrs-ri\lib

Add these libraries into web project.

Sample helloworld class:

************************************

package tr.edu.metu.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path(“/helloworld”)
public class HelloWorldService {

@GET
@Path(“/salutation”)
public Response getMsg(@QueryParam(“argument”) String msg) {

String output = “Message : ” + msg;

return Response.status(200).entity(output).build();

}

}

*******************************

 

Add these into web.xml

********************************

<servlet>
<servlet-name>sample-servlet</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>tr.edu.metu.ws</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>sample-servlet</servlet-name>
<url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

************************************

 

run the server.

You can access the web service via:

http://localhost:8080/YourWEBProject/webservices/helloworld/salutation?argument=merhaba

then you will get the message

Message : merhaba