Chapter 31. Embedded Container

RESTEasy JAX-RS comes with an embeddable server that can be run from your classpath. It packages the TJWS (Tiny Java Web Server) embeddable Servlet container with JAX-RS.
From the distribution, move the JARs in resteasy-jaxrs.war/WEB-INF/lib into your classpath. You must register your JAX-RS beans programmatically using the embedded server's Registry. Here's an example:

@Path("/")
public class MyResource {

   @GET
   public String get() { return "hello world"; }
 

   public static void main(String[] args) throws Exception 
   {
      TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
      tjws.setPort(8081);
      tjws.getRegistry().addPerRequestResource(MyResource.class);
      tjws.start();
   }
}

The server can either host non-encrypted or SSL-based resources, but not both. See the Java Documentation for TJWSEmbeddedJaxrsServer and its superclass TJWSServletServer for further information. The TJWS website is also very informative.
To use Spring, you will need the SpringBeanProcessor. Here is a pseudo-code example:

   public static void main(String[] args) throws Exception 
   {
      final TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
      tjws.setPort(8081);

      org.resteasy.plugins.server.servlet.SpringBeanProcessor processor = new SpringBeanProcessor(tjws.getRegistry(), tjws.getFactory();
      ConfigurableBeanFactory factory = new XmlBeanFactory(...);
      factory.addBeanPostProcessor(processor);

      tjws.start();
   }