JAX – RS Hello world example in Jersey 1.x

In this tutorial we see hello world example in jersey 1.x . There will be lot of differences between jersey 1.x and 2.x. The main purpose of this post is just want explain the configurations required for specific version of Jersey Framework. let us have a jump into example code in Jersey 1.

what is the main difference of web.xml configuration in  Jersey 1.x and Jersey 2.x

In Jersey 1 frame work we are using com.sun.jersey.spi.container.servlet.ServletContainer to configure in web.xml (see the web.xml in this post)  where as in  Jersey 2.0 on wards we are using org.glassfish.jersey.servlet.ServletContainer  to configure in web.xml, see the some of the Jersey 2 examples posted by me.

 

1. Create Dynamic web project in Eclipse.

restfulhelloword_jersey_1_proj

2. Write Java service class.

 

 

NOTE : I have not included all the required jersey jars in the source code please download it from here and copy to lib folder.

3. Configure the Jersey Container in web.xml

 

4. Run the Example

In the above java service class we have implemented the service “sayHello” and we can call this service by using below url.

http://localhost:8080/RestfulHelloWorld_Jersey_v_1/rest/hello

Here RestfulHelloWorld_Jersey_v_1 is our application context , rest will matching web.xml , and hello is the actual path configured to invoke “sayHello” service.
OUT PUT:

 

restfulhelloword_jersey_1

 

 

Download  Source Code

 

 

Posted in webservices and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">