28

I have been trying to figure out how to use JAX-RS for quite some time. I started from the very basic concepts and then to gradually understand the annotation styled programming, the meaning of @Path, @Get, @Post, etc.

To my understanding, as to what has been mentioned in a lot of places, JAX-RS is a framework that focuses on applying Java annotations to plain Java objects (Page 27, Bill Burke, RESTful Java).

I have then got confused beyond this point. If JAX-RS in itself is a framework that defines APIs dealing with annotations in order to implement RESTful web service, what's the meaning of "implementation of JAX-RS" such as "Jersey" and "JBoss Resteasy". Another layer on top of JAX-RS? Why do we need them?

Could someone provide me some insights about it? Many thanks!!!

ThangLeQuoc
  • 2,272
  • 2
  • 19
  • 30
lixiang
  • 1,941
  • 3
  • 20
  • 25

2 Answers2

35

JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.

Being implementations mean that the spec says "if you put @GET("/foo") on a method (bar()), you may access data X" - now in an app server, someone needs to go in and actually read your deployed code, parse the byte code with the @GET annotation and then if the user actually browses to e.g. http://localhost/foo get this web request to reach bar() and translate the return value of bar() into a http answer (e.g in XML or JSON representation).

So the spec with the name "JAX-RS" only provides the syntax and semantics of e.g. @GET, but the work of parsing requests, calling the right methods, marshalling the result values etc. need to be done by a package that implements the Spec.

Work on the version 2.0 of the standard has started as JRS-339.

See also http://en.wikipedia.org/wiki/Jax-rs

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
  • 1
    Thank you very much!! I understand they are implementations, but I can't understand the meaning of "being implementations of JAX-RS". I have added some further illustrations of my question in another post, would you please have a look at it? – lixiang Feb 15 '11 at 18:03
  • 6
    Got it!! In another post, Mike also mentioned that without all these implementations, JAX-RS is just a bench of interfaces. Thank you! – lixiang Feb 16 '11 at 02:33
31

JAX-RS is a specification for RESTful Web Services with Java. There is a reference implementation that is included in Java EE but since it is a specification, other frameworks can be written to implement the spec, and that includes Jersey, Resteasy, and others.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • 2
    Yes, exactly! I understand they are implementations, but i can't understand the meaning of "being implementations of JAX-RS". See, I have created a simple rest class and imported namespaces such as "javax.ws.rs.GET", "javax.ws.rs.Path", "javax.ws.rs.Produces";"javax.ws.rs.core.MediaType". I then deployed this class by using Tomcat server, and threw all jersey jars in lib and run it. Where has jersey been used?? Do the four imported namespaces belong to jersey? I have created another app with Resteasy approach in which the four imports were still used. I am confusing... – lixiang Feb 15 '11 at 18:02
  • 8
    Jersey is actually implementing the javax.ws.rs.* classes. Without using some implementation all you have are the interface classes, which can do nothing on their own. All implementations of JAX-RS use the same interfaces. – Mike Miller Feb 15 '11 at 20:51
  • 1
    Thank you!! I actually realized this point when I was sleeping and thinking through the couple of little projects I created! – lixiang Feb 16 '11 at 02:30
  • 1
    Jersey is actually the reference implementation! From the homepage: " Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation." – Ray Hulha Oct 21 '15 at 15:34
  • @RayHulha I find it amusing that I just found this question while looking what people thought about various implementations and was going to point out Jersey is the reference... only to find out someone did within the last 24 hours. On a 4.5 year old question. – Powerlord Oct 22 '15 at 14:26
  • I like to be thorough :) – Ray Hulha Oct 22 '15 at 21:09