Running JAX-RS applications on Tomcat

Running JAX-RS applications on vanilla Tomcat is not straight forward if you don't know the caveats. The short story is that you'll need to include extra runtime JARs and must set up a servlet in web.xml to bootsrap JAX-RS even though you're using an class.

These are the crucial bits I set up to run my JAX-RS,, on Apache Tomcat 8.0.24. Also note that this CXF servlet did not work on Tomcat 7.0.63 (for that version of Tomcat, you'll need to search out a different servlet to bootstrap JAX-RS).

There are different servlets that you can ues to bootstrap JAX-RS in your webapp. I found CXF to be the easiest to use:




This is the real pain of not using a JEE container (like JBoss or TomEE) but only a servlet container; you must wire up JAX-RS in your web application descriptor:

  <display-name>CXF Servlet</display-name>


The implementation, BookendsWS

Remember to implement the getClasses() method:

public Set<Class<?>> getClasses() {
     return new HashSet<Class<?>>(Arrays.asList(Pong.class, Root.class));

Want something that just works? has much more of a plug and play experience, much like you'd find with JBoss.

Using TomEE, you can just implement your and annotate your REST classes correctly and deploy the webapp. It just works, no need web.xml or extra runtime libraries are necessary.

JBoss will give you the same plugin and play experience, but if you really want to use Tomcat, just with the plug and play feature, TomEE will fit the bill perfectly.

Licensed under CC BY Creative Commons License ~ ✉ torstein.k.johansen @ gmail ~ 🐘 ~ 🐦 @torsteinkrause