Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-RS in relation to Jersey and JSRs

I'm trying to get my head around some concepts in Java:

  1. JSR(s): describe specifications, but carry no actual implementations. E.g. http://jsr311.java.net/ is the "home" for "Java™ API for RESTful Web Services". It serves as a common reference for all implementations of JSR-311.
  2. One can download the interfaces (?) of JSR-311 from http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api, however, unless you are implementing JSR-311 by yourself these have no particular value?
  3. JSR(s) will usually/always have a reference implementation. To find it you'll have to google "JSR XXX reference implementation" or see the specifications home page (e.g. http://jsr311.java.net/)
  4. For JSR-311 this reference implementation is Jersey. Using maven you can get the jersey server from http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9. Since Jersey provides an implementation according to the interfaces found in http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api, you only need to add Jersey as a dependency in your project and not the jsr311-api itself. (this applies to all JSR technologies?)
  5. Putting both http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api and http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9 as dependencies in your project will possibly cause classpath problems?

Am I completely off or onto someting?

like image 400
Mads Mobæk Avatar asked Dec 12 '11 15:12

Mads Mobæk


People also ask

Is JAX-RS and Jersey same?

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.

What is the use of JAX-RS?

JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Web Services. Its 2.0 version was released on the 24th May 2013. JAX-RS uses annotations available from Java SE 5 to simplify the development of JAVA based web services creation and deployment.

What is the difference between JAX-RS and JAX WS?

Actually,JAX-WS represents both RESTful and SOAP based web services. One way to think about it is that JAX-RS specializes in RESTful, while JAX-WS allows you more flexibility to choose between either, while at the same time being (in some cases) more complicated to configure.

Which of the following is the JAX-RS reference implementations?

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


1 Answers

  1. Yes, this isn't anything new. Think about JDBC, java provides the interfaces (Connection, Statement, ResultSet etc) but it is up to database vendors to provide implementations.

  2. If you're using a JSR-311 implementation like Jersey or Apache CXF then you'll annotate your classes with the javax.ws.rs annotations, such as @Path, @GET, @Produces etc. This is why you need to explicitly have JSR-311 as a maven dependency.

  3. Yes, usually. Have a look at the JSR list on wiki.

  4. You need both the JSR and the implementation. The annotations are in the JSR, the implementation provides supporting classes, such as com.sun.jersey.spi.container.servlet.ServletContainer.

  5. No, it is necessary to have both as dependencies (see point 4); you won't get classpath conflicts.

like image 143
Qwerky Avatar answered Oct 15 '22 14:10

Qwerky