< any static
static content >
WEB - INF /
web . xml
com / restfully / shop / domain /
Customer . class
com / restfully / shop / services /
CustomerResource . class
ShoppingApplication . class
Our application server's servlet container publishes everything outside the WEB-INF/ direct-
ory of the archive. This is where you would put static HTML files and images that you want
to expose to the outside world. The WEB-INF/ directory has two subdirectories. Within the
classes/ directory, you can put any Java classes you want. They must be in a Java package
structure. This is where we place all of the classes we wrote and compiled in this chapter.
The lib/ directory can contain any third-party JARs we used with our application. Depending
on whether your application server has built-in support for JAX-RS or not, you may have to
place the JARs for your JAX-RS vendor implementation within this directory. For our cus-
tomer example, we are not using any third-party libraries, so this lib/ directory may be
We are almost finished. All we have left to do is to create a WEB-INF/web.xml file within
<? xml version = "1.0" encoding = "UTF-8" ?>
< 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
version = "3.0" >
</ web - app >
Because this example deploys within a Java EE application server or standalone Servlet 3.x
container, all we need is an empty web.xml file. The server will detect that an Application
class is within your WAR and automatically deploy it. Your application is now ready to use!
Writing a Client
If you need to interact with a remote RESTful service like we just created, you can use the
JAX-RS 2.0 Client API. The Client interface is responsible for managing client HTTP con-
create a customer by invoking the remote services defined earlier in this chapter.