Java Reference
In-Depth Information
For standalone Servlet 3.x containers like Tomcat and Jetty, most JAX-RS implementations
can seamlessly integrate JAX-RS just as easily as with Java EE. They do this through the
Servlet 3.0 ServletContainerInitializer SPI, which we will not cover here. The only
difference between standalone servlet deployments and Java EE is that your WAR deploy-
ments will also need to include the libraries of your JAX-RS implementation.
Deploying a JAX-RS application is very easy in a JAX-RS-aware servlet container. You still
need at least an empty web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
<web-app xmlns= "http://java.sun.com/xml/ns/javaee"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version= "3.0" >
</web-app>
</web-app>
If you have at least one Application class implementation annotated with @Applica-
tionPath , the JAX-RS-aware container will automatically deploy that Application . For
example:
package
package com . restfully . shop . services ;
import
import javax.ws.rs.core.Application
javax.ws.rs.core.Application ;
import
import javax.ws.rs.ApplicationPath
javax.ws.rs.ApplicationPath ;
@ApplicationPath ( "/root" )
public
public class
class ShoppingApplication
ShoppingApplication extends
extends Application {
public
public ShoppingApplication () {}
public
public Set < Class <?>> getClasses () {
HashSet < Class <?>> set = new
new HashSet < Class <?>>();
set . add ( CustomerResource . class );
set . add ( OrderResource . class );
set . add ( ProduceResource . class );
return
return set ;
}
public
public Set < Object > getSingletons () {
JsonWriter json = new
new JsonWriter ();
CreditCardResource service = new
new CreditCardResource ();
HashSet < Object > set = new
new HashSet ();
Search WWH ::




Custom Search