JAX-RS @PATH for URI – Jersey

In this tutorial we will we see about JAX-RS @PATH annotation used in URI of RESTful web service api.

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 2.x maven dependency configuration below. If you are new to maven refer our maven tutorials.

Jersey 2.x dependency in pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <name>RestTutorials Maven Webapp</name>
      <!-- JAX-RS -->
        <!-- Jersey 2.19 -->


package com.ehowtonow.webservice;

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

public class RestPathService {

 public Response getCaptain() {
  return Response.status(200).entity("Captain : Dhoni").build();


 public Response getStarPlayer() {
  return Response.status(200).entity("Cricket God : Sachin Tendulkar")


In this class getCaption() resource accessed by @PATH annotation declared for class with base URI and gerStarplayer() resource accessed by base URI + /cricket/starplayer. ‘starplayer’ is annotation for getStrarPlayer() method

Configure Jersey 2.x Servlet dispatcher

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

	<display-name>Restful Webservice Example</display-name>


Now your web service is ready to run.Your Web Service available at following url

http://your domain:port/Project Name/url pattern/path

http://localhost:8080/RestTutorials/rest/cricket – access first method

http://localhost:8080/RestTutorials/rest/cricket/starplayer – access second method


Jax-RS @PathParam with @Path

Always we need to use @PathParam JAX-RS annotation with @Path annotation. We will see the details example about @PathParam in next tutorials. In this tutorial just going to show how to use @PathParam with @Path .


package com.ehowtonow.webservice;

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

public class RestPathParamService {

 public Response getCricketer(@PathParam("name") String cricketer) {
  return Response.status(200).entity("Young Shining Star : " + cricketer)


you can access this resource by using following url


here Kholi is parameter passed with URL.This parameter accessed by using @PathParam annotation

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. JAX-RS Send List using QueryParam Annotation
  2. JAX-RS @PathParm Web service Example
  3. Restful Webservice HelloWorld Example Jersey 1.x
  4. JAX-RS @MatrixParam Restful Webservice
  5. Download Text file using JAX-RS RESTful Webservice
  6. JAX-RS @PATH for URI – Jersey
  7. JAX-RS Web service to Consume JSON using Jersey 1.x
  8. File Upload using JAX-RS RESTful Webservice (Jersey 2.x)
  9. JAX-RS QueryParam – Jersey
  10. JAX-RS @GET RESTful webservice
  11. RESTful Web service to consume JSON and Produce XML – Jersey 1.x
  12. JAX-RS @POST using RESTful web service – Jersey 1.x
  13. JAX-RS @FormParam Web service example
  14. JAX-RS Get HTTP Headers using @Context
  15. JAX-RS to Produce JSON using Jackson – Jersey 1.x

Be the first to comment

Leave a Reply