Your Location is: Home > Jax-rs

How is JAX RS and JAX WS supported by Tomcat? [duplicate]

From: Madagascar View: 1089 nano 

Question

As of my understanding java EE application servers have mainly two types of containers. Namely web container and EJB container.

I managed to run a JAX-RS application which used Jersey as its implementation, in Tomcat. As I know Tomcat is only a web container. In order to run the web service in tomcat, the jersey jars had to be bundled into the war file because out of the box, Tomcat did not have the jersey jars. This raised me a question.

Does tomcat uses another implementation of JAX-RS other than Jersey? If Yes what is it?

if No,

I could not run the Jax-RS application without the jars bundled into the war file, this means JAX-RS apps need something more than what the web containers offer. It means they do not run in a web container. then in which container does it run?

Best answer

"Does tomcat uses another implementation of JAX-RS other than Jersey?"

I don't know if you're asking if Tomcat has an implementation or if it is capable of running other implementations beside Jersey.

The answer to the former is no. Vanilla Tomcat does not support JAX-RS out the box. It is not an EE server, but simply a Servlet container. But TomEE+ (built on Tomcat) has support (using CXF).

The answer to the latter is yes. You just need to add that implementations jars and configure the app properly

"I could not run the Jax-RS application without the jars bundled into the war file"

Yup, you can't. For the simple fact there is no implementation to support the JAX-RS runtime.

"It means they do not run in a web container. then in which container does it run?"

It does run in the Servlet container. JAX-RS is actually built on top of Servlets. For Jersey, it uses the ServletContainer. Tomcat will ship off requests to the Jersey Servlet, and Jersey will process the request through configured provider and resources and spit out the response back to the container. The container will send the response to the client. (See first link below)


If you are looking for a Java EE application server, that supports the whole EE spec, you can look at Glassfish (it uses Jersey as it's implementation), JBoss/Wildfly (it uses Resteasy), TomEE+ mentioned above (uses CXF)


Here are some related reads you might find interesting: