Chapter 2. Modules and dependencies
Prev |  | Next

Links: Table of Contents | Single HTML

## Chapter 2. Modules and dependencies

## 2.1. Java SE Compatibility

All Jersey components are compiled with Java SE 6 target. It means, you will also need at least Java SE 6 to be able to compile and run your application.

## 2.2. Introduction to Jersey dependencies

Jersey is built, assembled and installed using Apache Maven. Non-snapshot Jersey releases are deployed to the Central Maven Repository. Jersey is also being deployed to Java.Net Maven repositories, which contain also Jersey SNAPSHOT versions. In case you would want to test the latest development builds check out the Java.Net Snapshots Maven repository.

An application that uses Jersey and depends on Jersey modules is in turn required to also include in the application dependencies the set of 3rd party modules that Jersey modules depend on. Jersey is designed as a pluggable component architecture and different applications can therefore require different sets of Jersey modules. This also means that the set of external Jersey dependencies required to be included in the application dependencies may vary in each application based on the Jersey modules that are being used by the application.

Developers using Maven or a Maven-aware build system in their projects are likely to find it easier to include and manage dependencies of their applications compared to developers using ant or other build systems that are not compatible with Maven. This document will explain to both maven and non-maven developers how to depend on Jersey modules in their application. Ant developers are likely to find the Ant Tasks for Maven very useful.

## 2.3. Common Jersey Use Cases

### 2.3.1. Servlet based application on Glassfish

If you are using Glassfish application server, you don't need to package anything with your application, everything is already included. You just need to declare (provided) dependency on JAX-RS API to be able to compile your application.

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>

If you are using any Jersey specific feature, you will need to depend on Jersey directly.

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>
    <!-- if you are using Jersey client specific features -->
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>

### 2.3.2. Servlet based server-side application

Following dependencies apply to application server (servlet containers) without any integrated JAX-RS implementation. Then application needs to include JAX-RS API and Jersey implementation in deployed application.

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core"  -->
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.4</version>
    </dependency>
    <!-- Required only when you are using JAX-RS Client -->
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.4</version>
    </dependency>

### 2.3.3. Client application on JDK

Applications running on plain JDK using only client part of JAX-RS specification need to depend only on client. There are various additional modules which can be added, like for example grizzly or apache connector (see dependencies snipped below). Jersey client runs by default with plain JDK (using HttpUrlConnection). See Chapter 5, Client API. for more details.

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.4</version>
    </dependency>

Currently available connectors:

    <dependency>
        <groupId>org.glassfish.jersey.connectors</groupId>
        <artifactId>jersey-grizzly-connector</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.connectors</groupId>
        <artifactId>jersey-apache-connector</artifactId>
        <version>2.4</version>
    </dependency>

### 2.3.4. Server-side application on supported containers

Apart for a standard JAX-RS Servlet-based deployment that works with any Servlet container that supports Servlet 2.5 and higher, Jersey provides support for programmatic deployment to the following containers: Grizzly 2 (HTTP and Servlet), JDK Http server and Simple Http server. This chapter presents only required maven dependencies, more information can be found in Chapter 4, Deploying a RESTful Web Service.

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-servlet</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jdk-http</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-simple-http</artifactId>
        <version>2.4</version>
    </dependency>

## 2.4. List of modules

The following chapters provide an overview of all Jersey modules and their dependencies with links to the respective binaries (follow a link on a module name to get complete set of downloadable dependencies).

Table 2.1. Jersey Core

Core
jersey-client | Jersey core client implementation.
jersey-common | Jersey core common packages.
jersey-server | Jersey core server implementation.

Table 2.2. Jersey Containers

Containers
jersey-container-grizzly2-http | Grizzly 2 Http Container.
jersey-container-grizzly2-servlet | Grizzly 2 Servlet Container.
jersey-container-jdk-http | JDK Http Container.
jersey-container-servlet | Jersey core Servlet 3.x implementation.
jersey-container-servlet-core | Jersey core Servlet 2.x implementation.
jersey-container-simple-http | Simple Http Container.

Table 2.3. Jersey Connectors

Connectors
jersey-grizzly-connector | Jersey Client Transport via Grizzly.
jersey-apache-connector | Jersey Client Transport via Apache.

Table 2.4. Jersey Media

Media
jersey-media-json-jackson | Jersey JSON Jackson entity providers support module.
jersey-media-json-jettison | Jersey JSON Jettison entity providers support module.
jersey-media-json-processing | Jersey JSON-P (JSR 353) entity providers support proxy module.
jersey-media-moxy | Jersey JSON entity providers support module based on EclipseLink MOXy.
jersey-media-multipart | Jersey Multipart entity providers support module.
jersey-media-sse | Jersey Server Sent Events entity providers support module.

Table 2.5. Jersey Extensions

Extensions
jersey-bean-validation | Jersey extension module providing support for Bean Validation (JSR-349) API.
jersey-mvc | Jersey extension module providing support for MVC.
jersey-mvc-freemarker | Jersey extension module providing support for Freemarker templates.
jersey-mvc-jsp | Jersey extension module providing support for JSP templates.
jersey-proxy-client | Jersey extension module providing support for (proxy-based) high-level client API.
jersey-servlet-portability | Library that enables writing web applications that run with both Jersey 1.x and Jersey 2.x servlet containers.
jersey-wadl-doclet | A doclet that generates a resourcedoc xml file: this file contains the javadoc documentation of resource classes, so that this can be used for extending generated wadl with useful documentation.

Table 2.6. Jersey Test Framework

Test Framework
jersey-test-framework-core | Jersey Test Framework Core.
jersey-test-framework-provider-bundle | Jersey Test Framework Providers Bundle.
jersey-test-framework-provider-default-client | Jersey Test Framework Default Client Provider.
jersey-test-framework-provider-external | Jersey Test Framework - External container.
jersey-test-framework-provider-grizzly2 | Jersey Test Framework - Grizzly2 container.
jersey-test-framework-provider-inmemory | Jersey Test Framework - InMemory container.
jersey-test-framework-provider-jdk-http | Jersey Test Framework - JDK HTTP container.
jersey-test-framework-provider-simple | Jersey Test Framework - Simple HTTP container.

Table 2.7. Jersey Glassfish Bundles

Glassfish Bundles
jersey-gf-cdi | Jersey CDI for GlassFish integration.
jersey-gf-ejb | Jersey EJB for GlassFish integration.

Table 2.8. Jersey Examples

Examples
clipboard | Jersey clipboard example.
clipboard-programmatic | Jersey programmatic resource API clipboard example.
exception-mapping | Jersey example showing exception mappers in action.
helloworld | Jersey annotated resource class "Hello world" example.
helloworld-programmatic | Jersey programmatic resource API "Hello world" example.
helloworld-pure-jax-rs | Example using only the standard JAX-RS API's and the lightweight HTTP server bundled in JDK.
http-trace | Jersey HTTP TRACE support example
https-clientserver-grizzly | Jersey HTTPS Client/Server example on Grizzly.
jaxb | Jersey JAXB example.
jaxrs-types-injection | Jersey JAX-RS types injection example.
json-jackson | Jersey JSON with Jackson example.
json-jettison | Jersey JSON with Jettison JAXB example.
json-moxy | Jersey JSON with MOXy example.
json-with-padding | Jersey JSON with Padding example.
managed-client | Jersey managed client example.
osgi-helloworld-webapp | OSGi Helloworld.
osgi-helloworld-webapp | OSGi Helloworld - bundle.
osgi-helloworld-webapp | OSGi Helloworld - war.
osgi-http-service | OSGi Helloworld.
osgi-http-service | OSGi Helloworld.
reload | Jersey resource configuration reload example.
server-async | Jersey JAX-RS asynchronous server-side example.
server-async-managed | Jersey JAX-RS asynchronous server-side example with custom Jersey executor providers.
server-async-standalone | Standalone Jersey JAX-RS asynchronous server-side processing example.
server-sent-events | Jersey Server-Sent Events example.
simple-console | Jersey Simple Console example.
sse-twitter-aggregator | Jersey SSE Twitter Message Aggregator Example.
system-properties-example | Jersey system properties example.
xml-moxy | Jersey XML MOXy example.

Table 2.9. Jersey Examples - WebApps

Examples - WAR
bean-validation-webapp | Jersey Bean Validation (JSR-349) example.
bookmark | Jersey Bookmark example.
bookmark-em | Jersey Bookmark example using EntityManager.
bookstore-webapp | Jersey MVC Bookstore example.
cdi-webapp | Jersey CDI example.
extended-wadl-webapp | Extended WADL example.
freemarker-webapp | Jersey Freemarker example.
helloworld-webapp | Jersey annotated resource class "Hello world" example.
https-server-glassfish | Jersey HTTPS server on GlassFish example.
jersey-ejb | Jersey EJB example.
json-processing-webapp | Jersey JSON-P (JSR 353) example.
managed-beans-webapp | Jersey Managed Beans Web Application example.
managed-client-simple-webapp | Jersey Managed Client Simple Webapp example.
managed-client-webapp | Jersey managed client web application example.
multipart-webapp | Jersey Multipart example.
sse-item-store-webapp | Jersey SSE-based item store example.

Prev |  | Next
Chapter 1. Getting Started | Home | Chapter 3. JAX-RS Application, Resources and Sub-Resources