Chapter 16. Examples for Chapter 3

Chapter 3 walked you through a very basic example of creating a JAX-RS service. This service was a simple in-memory customer database. It was modeled as a singleton JAX-RS resource class and exchanged simple XML documents.

This chapter takes the code from Chapter 3 and shows you how to run it using the downloadable workbook example code. I’ll walk you through how the code is structured on disk as well as how the examples use the Maven build system to compile, build, and run it.

Build and Run the Example Program

Perform the following steps:

  1. Open a command prompt or shell terminal and change to the ex03_1 directory of the workbook example code.

  2. Make sure your PATH is set up to include both the JDK and Maven, as described in Chapter 15.

  3. Perform the build by typing maven install. Maven uses pom.xml to figure out what to compile, build, and run the example code.

Before we examine the build file for this example, you might want to take a quick look at the Maven utility at its Apache website at

Maven is a build-by-convention tool. It expects that your source code be laid out in a certain directory structure. From this standard directory structure, it knows how to automatically find, compile, and package your main class files. It also knows where your test code is and will compile and run it.

Every exercise in this book will follow the directory structure shown in Figure 16-1. Table 16-1 describes the purpose of the various directories. ...

Get RESTful Java with JAX-RS now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.