Sumit Arora
Sumit Arora

Reputation: 5241

Difference between Apache CXF Runtime JAX RS Frontend and 'javax.ws.rs' (from Oracle)

I am developing web services for a project, and I supposed to add the dependency on a pom file for 'javax.ws.rs' and 'javax.ws.rs.core'. Since I am using Apache CXF for the required REST API Implementation. I have couple of question:

  1. What is this 'javax.ws.rs' (from Oracle), Is this only JAx-RS API Specification ? If this is true that its has only APIs then how its helpful ? Why don't we only use the apache cxf or jersey and add that as a dependency to maven?

2.To implement I definitely need to use 'Apache CXF Runtime JAX RS Frontend', then what is the difference between 'javax.ws.rs' and 'Apache CXF'.

Please rephrase my question if doesn't make the sense but it makes sense in a different way.

Upvotes: 1

Views: 2288

Answers (1)

David Lizárraga
David Lizárraga

Reputation: 1192

  1. javax.ws.rs is the package that contains the JAX-RS API Specification. It only contains the interfaces, so to use jax-rs in a project you will need an implementation for these interfaces, for example Jersey or CXF.
  2. (I guess 1 already answers this one as well).

The same happens in other cases, like JAX-WS, where you have the API specification and you need an implementation to actually use it. In this case, the JAX-WS Reference Implementation is already included in the jdk and you would not need to provide another one, although you could provide CXF JAX-WS implementation if you wanted to.

Maven dependencies

When you use CXF or Jersey, you dont need to include a dependency explicitly for javax.ws.rs, as it's already included as a transitive dependency for those, meaning that it will be downloaded automatically.

In your case, to use CXF you will need to add these dependencies in your pom file:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>${cxf.version}</version>
</dependency>

That's all, you don't need to include any dependency for javax.ws.rs.

Upvotes: 4

Related Questions