107

I really cant understand what really is jersey..

What I know is that Jax-RS is an API for building REST web services, and jersey? I got some information and all say the same: "jersey is an implementation of Jax-RS". But what it means?

If jax-rs is an API, why we need jersey for create a rest web service? Is jersey a couple of more libs to aim with jax-rs? if yes, jax-rs is an incomplete API?

T J
  • 42,762
  • 13
  • 83
  • 138
user1851366
  • 256
  • 6
  • 20
  • 41
  • 13
    Jersey in an *implementation* of the JAX-RS *specification* – Brian Roach Jul 26 '13 at 18:45
  • 1
    Jersey just a interface to use JAX-rs in more easier way. JAX-RS don't provided servlet but Jersey does. Jersey provides a library to implement Restful webservices in a Java servlet container, Jersey provides a servlet implementation which scans predefined classes to identify RESTful resources. In your web.xml configuration file your register this servlet for your web application. – taymedee Jan 03 '15 at 04:46
  • 1
    JAX-RS is a specification (which basically tells what to implement/follow) and Jersey is an implementation (which means how those specifications should be implemented). We can have multiple implementations for a Specification. We have libs for JAX-RS because we can use JAX-RS API's in your code so that in future if you change your implementation (in this case Jersey to something else) you code will still work fine. You can relate it with your interface and implementation class. – Vishal Akkalkote Mar 19 '18 at 08:30
  • @VishalAkkalkote Hello, I am trying to wrap my head around this. I use Websphere 8.5 at work, and I am trying to write REST services using JAX-RS, but all tutorials show JAX-RS with Jersy. Are you saying, I can write the same EXACT code and it will work even if I don't use Jersy lib? – superPhreshHackerKid Jul 08 '18 at 23:32
  • 1
    @superPhreshHackerKid Yes. it should work provided you will use one of implementation of JAX-RS. e.g. Apache CXF – Vishal Akkalkote Sep 09 '18 at 17:24

5 Answers5

105

JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation.

Ale Zalazar
  • 1,875
  • 1
  • 11
  • 14
  • 16
    So jax-rs say what we should do,and jersey do it?? Thats make sense,but why there are jax-rs libs?? – user1851366 Jul 26 '13 at 19:08
  • 22
    For example: JAX-RS gives you a set of interfaces (standard Java interfaces) which are implemented by Jersey. So that set of interfaces (or classes) are needed as a dependency to be implemented. – Ale Zalazar Jul 26 '13 at 19:12
  • 3
    well,thats make sense... But,we always need others classes for implement jax-rs,right? Like this one,jersey.. – user1851366 Jul 26 '13 at 19:27
  • 12
    That's correct. i.e. JAX-RS gives you javax.ws.rs.core.Request interface and Jersey implements it in com.sun.jersey.spi.container.ContainerRequest – Ale Zalazar Jul 26 '13 at 19:39
  • 10
    is this the same as JPA being the specification and hibernate being one of its implementation? – DesirePRG Apr 19 '15 at 11:25
  • @DesirePRG exactly. – Ale Zalazar Jun 22 '23 at 22:20
26

Straight from the jersey site

Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides its own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development. Jersey also exposes numerous extension SPIs so that developers may extend Jersey to best suit their needs.

anotherdave
  • 6,656
  • 4
  • 34
  • 65
orangegoat
  • 2,523
  • 1
  • 15
  • 17
  • 3
    Well,i readed about that,but dont ask my question. Why we need jersey if we have jax-rs? jax is incomplete? – user1851366 Jul 26 '13 at 18:56
  • 29
    @user1851366 Imagine that there is a benevolent organization that creates (and gives away for free) designs for cars. Manufacturers around the world recognize that those designs are good and implement real cars based on those designs. Well, JAX-RS is just like a plan or design on how to build RESTful APIs, and software manufacturers recognize it and implement those ideas with real RESTful APIs, one of this is called Jersey, but there are others (i.e. RESTEasy). Just as many other manufacturers besides Toyota may use the designs to create their own version of cars. – Edwin Dalorzo Aug 15 '13 at 12:58
6

JAX-RS is an specification and Jersey is a JAX-RS implementation.- True

This can be understood relating it to OOPS principles JAX-RS is an Interface and Jersey is a class implementing that interface.

These Specification creates a STANDARD for developing and using the web services.

There are other JAX-RS implementations too like wink, RestEasy.

JAX-RS is a specification which specifies how can we implement the web services,that what would be input type, input format, output type, its format, its configuration etc.Its Just a type declaration and its implementation are these libraries, Jersey, wink RestEasy etc.

Further, Java also have specification like JPA(Java Persistence API) and like mentioned above there is Hibernate which is an implementation of JPA.

3

JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation. Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides its own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development.

Horia
  • 48
  • 6
2

Using JAX-RS alone can not implement REST, need to register Jersey as the servlet dispatcher for REST requests on web.xml

A standard and portable JAX-RS API has been designed. 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.

Jersey framework is more than the JAX-RS Reference Implementation. Jersey provides it’s own API that extend the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development. Source

For more

Restlet and Jersey are two of the most popular implementation of JAX-RS used for developing RESTful web services in Java ecosystem but there are a couple of other implementation also exist e.g. Apache Wink, Apache CXF, and JBoss RESTEasy. Source

Premraj
  • 72,055
  • 26
  • 237
  • 180