Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxrs-api VS jsr311-api VS javax.ws.rs-api VS jersey-core VS jaxrs-ri

I have googled around quite a bit still am confused as to what each of the above exactly mean.

Here is my understanding of it:

  • jaxrs-api : contains only api. No implementation. But how is it different from JSR311
  • jsr311-api : JSR311 it is a specification request. Which means it is supposed to be a document. Why then is it a jar?
  • javax.ws.rs-api: Is it an implementation?
  • jersey-core(/jersey client): Is an implementation of JSR311.

I downloaded each jar and tried to decompile and see what is inside it, but I am only able to find interfaces in all of them and not the implementation.

I am facing these questions in the context of duplicate warnings generated by maven shade plugin, and need proper understanding of the above to figure out which ones to exclude and why.

like image 203
Gadam Avatar asked Aug 19 '15 22:08

Gadam


People also ask

Is Jax and Jersey RS the 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 JAX-RS specification?

Jakarta RESTful Web Services, (JAX-RS; formerly Java API for RESTful Web Services) is a Jakarta EE API specification that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern.

What is JAX ra?

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.


1 Answers

I'll first get to the question

"JSR311 it is a specification request. Which means it is supposed to be a document. Why then is it a jar?"

Except the last (jersey-core), all those jars are "specification" jars. The JAX-RS (as well as many other Java) specifications define contracts (or interfaces) that implementators should implement the specified behavior for.

So basically all the classes specified in the specification should be in the jar as contracts. End users of the jars can use them for the contracts. but there is no implementation. You need to have an actually implementation to run the application, though the spec API jar is enough to compile a complete JAX-RS compliant application.

For example, if we have one of those spec API jars on the classpath, we can author an entire JAX-RS application and compile it, but in order to run it, if we don't have the actual implementation, we need to deploy to a server that has the actual implementation of that spec version, for example JBoss or Glassfish


  • jaxrs-api - This is RESTeasy's packaging of the spec. It is not the official spec jar, but it does adhere to the spec contracts. RESTeasy uses this jar for the entire spec line, i.e. 1.x - current. Though the jar does change internals to adhere to the different JAX-RS versions.

  • jsr311-api - This is the official spec jar for the JAX-RS 1.x line.

  • javax.ws.rs-api - This is the official spec jar for the JAX-RS 2.x line.

  • jersey-core - This is a partial implementation of the spec. The rest of the implementation is contained inside other Jersey jars. Note that in earlier versions of Jersey, they actually packaged the JAX-RS spec APIs into this jar. It wasn't until later that Jersey started using the official spec jars.

  • jaxrs-ri - This is the complete Jersey 2.x implementation packaged into one jar. The "ri" mean reference implementation, which is what Jersey is: the JAX-RS reference implementation. If you are not using a dependency manager like Maven, you might want to just use this single jar instead of having to use all the separate jars that Jersey comes with.

Other Resources

  • Java API for RESTful Services (JAX-RS) to read details of the different spec versions.
  • Complete implementation for RESTeasy distribution. RESTeasy 3.x line if the JAX-RS 2.x implementation, and RESTeast 2.x/1.x id for the JAX-RS 1.x line
  • Complete distribution of Jersey implementation. You can find the JAX-RS 2.x implementation in the "Jersey JAX-RS 2.0 RI bundle" link at the top of the page. There is also at the bottom links to the Jersey 1.x line distribution, which adheres to the JAX-RS 1.x spec.

Also note that though different implementation adhere to the spec, each implementation has its own set of extra features. To learn more you should go through the documentation of the different implementation. The three most popular implementations are Jersey, RESTeasy, and CXF

like image 161
Paul Samsotha Avatar answered Oct 03 '22 10:10

Paul Samsotha