Movatterモバイル変換


[0]ホーム

URL:


Chapter 11. Dependencies
Prev   Next

Links:Table of Contents |Single HTML

Chapter 11. Dependencies

Table of Contents

11.1. Core server
11.2. Core client
11.3. Container
11.3.1. Grizzly HTTP Web server
11.3.2. Grizzly Servlet container
11.3.3. Simple HTTP Web server
11.3.4. Light weight HTTP server
11.3.5. Servlet
11.4. Entity
11.4.1. JAXB
11.4.2. Atom
11.4.3. JSON
11.4.4. Mail and MIME multipart
11.4.5. Activation
11.5. Tools
11.6. Spring
11.7. Guice
11.8. Jersey Test Framework

Jersey is built, assembled and installed using Maven. Jersey is deployed to the Java.Net maven repository at the following location:http://maven.java.net/. The Jersey modules can be browsed at the following location:https://maven.java.net/content/repositories/releases/com/sun/jersey. Jars, Jar sources, Jar JavaDoc and samples are all available on the java.net maven repository.

A zip file containing all maven-based samples can be obtainedhere. Individual zip files for each sample may be found by browsing thesamples directory.

An application depending on Jersey requires that it in turn includes the set of jars that Jersey depends on. Jersey has a pluggable component architecture so the set of jars required to be include in the class path can be different for each application.

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

Developers using maven are likely to find it easier to include and manage dependencies of their applications than developers using ant or other build technologies. This document will explain to both maven and non-maven developers how to depend on Jersey for their application. Ant developers are likely to find theAnt Tasks for Maven very useful. For the convenience of non-maven developers the following are provided:

Jersey's runtime dependences are categorized into the following:

All dependences in this documented are referenced by hyper-links

11.1. Core server

Maven developers require a dependency on thejersey-server module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-server</artifactId>    <version>1.19.1</version></dependency>

If you want to depend on Jersey snapshot versions the following repository needs to be added to the pom:

<repository>    <id>snapshot-repository.java.net</id>    <name>Java.net Snapshot Repository for Maven</name>    <url>https://maven.java.net/content/repositories/snapshots/</url>    <layout>default</layout></repository>

Non-maven developers require:

or, if using the jersey-bundle:

For Ant developers theAnt Tasks for Maven may be used to add the following to the ant document such that the dependencies do not need to be downloaded explicitly:

<artifact:dependencies pathId="dependency.classpath">  <dependency groupId="com.sun.jersey"              artifactId="jersey-server"              version="1.19.1"/>  <artifact:remoteRepository                             url="http://maven.java.net/" />  <artifact:remoteRepository                             url="http://download.java.net/maven/1"                             layout="legacy" /></artifact:dependencies>

The path id “dependency.classpath” may then be referenced as the classpath to be used for compiling or executing.

By default Jersey will utilize theClasspathResourceConfig if an alternative is not specified.

11.2. Core client

Maven developers require a dependency on thejersey-client module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-client</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:

or, if using the jersey-bundle:

The use of client with the Apache HTTP client to make HTTP request and receive HTTP responses requires a dependency on thejersey-apache-client module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.contribs</groupId>    <artifactId>jersey-apache-client</artifactId>    <version>1.19.1</version></dependency>

11.3. Container

11.3.1. Grizzly HTTP Web server

Maven developers, deploying an application using the Grizzly2 HTTP Web server, require a dependency on thejersey-grizzly2 module.

Non-maven developers require:jersey-grizzly2.jar,grizzly-http-server.jar, andgrizzly-http.jar

11.3.2. Grizzly Servlet container

Maven developers, deploying an application using the Grizzly Servlet container, require a dependency on thejersey-grizzly2-servlet module.

Non-maven developers require:jersey-grizzly2-servlet.jar,grizzly-http-servlet.jar,jersey-grizzly2.jar,javax.servlet-3.1.jar

11.3.3. Simple HTTP Web server

Maven developers, deploying an application using the Simple HTTP Web server, require a dependency on thejersey-simple-server module.

11.3.4. Light weight HTTP server

Deploying an application using the light weight HTTP server requires no additional dependences, as Java SE 6 already contains everything needed.

11.3.5. Servlet

Deploying an application on a servlet container requires a deployment dependency with that container.

See the Java documentationhere on how to configure the servlet container.

Using servlet:com.sun.jersey.spi.container.servlet.ServletContainer requires a dependency on thejersey-servlet module.

Maven developers using servlet:com.sun.jersey.server.impl.container.servlet.ServletAdaptor in a non-EE 5 servlet require a dependency on thepersistence-api module in addition.

Non-Maven developers require:persistence-api.jar

11.4. Entity

11.4.1. JAXB

XML serialization support of Java types that are JAXB beans requires a dependency on the JAXB reference implementation version 2.x or higher (see later for specific version constraints with respect to JSON support). Deploying an application for XML serialization support requires no additional dependencies, since Java SE 6 ships with JAXB 2.x support. Alternatively, instead of JAXB RI, you can use MOXy as your JAXB implementation (version of 2.3.x or higher is required)

11.4.1.1. JAXB RI (reference implementation)

Maven developers, using JSON serialization support of JAXB beans when using the MIME media typeapplication/json require a dependency on thejersey-json module (no explicit dependency on jaxb-impl is required). This module depends on the JAXB reference implementation version 2.1.12 or greater, and such a version is required when enabling support for the JAXB natural JSON convention. For all other supported JSON conventions any JAXB 2.x version may be utilized. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-json</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:

and additionally, if not depending on thejersey-bundle.jar, non-maven developers require:jersey-json.jar

Note: Jersey JSON module of version 1.13 and later requires thejackson-core-asl.jar library to be present on the classpath.

Maven developers, using Fast Infoset serialization support of JAXB beans with using the MIME media typeapplication/fastinfoset require a dependency on thejersey-fastinfoset module (no dependency on jaxb-impl is required). The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-fastinfoset</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:

and additionally, if not depending on thejersey-bundle.jar, non-maven developers require:jersey-fastinfoset.jar

11.4.1.2. MOXy

Maven developers, using JSON serialization support of JAXB beans when using the MIME media typeapplication/json require a dependency on thejersey-json module (explicit dependency on org.eclipse.persistence.moxy is required). The following dependencies need to be added to the pom:

<dependency>     <groupId>com.sun.jersey</groupId>     <artifactId>jersey-json</artifactId>     <version>1.19.1</version>     <exclusions>         <exclusion>             <exclusion>com.sun.xml.bind<exclusion>             <exclusion>jaxb-impl<exclusion>         </exclusion>     </exclusions></dependency><dependency>    <groupId>org.eclipse.persistence</groupId>    <artifactId>org.eclipse.persistence.moxy</artifactId>    <version>2.3.2</version></dependency>

Also an additional repository should be added to the pom:

<repository>    <id>eclipselink.repository</id>    <name>Eclipse Maven Repository</name>    <url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url>    <layout>default</layout></repository>

Non-maven developers require:

and additionally, if not depending on thejersey-bundle.jar, non-maven developers require:jersey-json.jar

For further information on how to set MOXy as your JAXB provider, refer to the:Specifying EclipseLink MOXy as Your JAXB Provider

Note: Jersey JSON module of version 1.13 and later requires thejackson-core-asl.jar library to be present on the classpath.

11.4.2. Atom

The use of the Java typesorg.apache.abdera.model.{Categories, Entry, Feed, Service} requires a dependency on Apache Abdera.

Maven developers require a dependency on thejersey-atom-abdera module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.contribs</groupId>    <artifactId>jersey-atom-abdera</artifactId>    <version>1.19.1</version></dependency>

The use of the Java typescom.sun.syndication.feed.atom.Entry andcom.sun.syndication.feed.atom.Feed requires a dependency on ROME version 0.9 or higher.

Maven developers require a dependency on thejersey-atom module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-atom</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:

and additionally, if not depending on thejersey-bundle.jar, non-maven developers require:jersey-atom.jar

11.4.3. JSON

The use of the Java typesorg.codehaus.jettison.json.JSONObject andorg.codehaus.jettison.json.JSONArray requires Jettison version 1.1 or higher.

Maven developers require a dependency on thejersey-json module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey</groupId>    <artifactId>jersey-json</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:jettison.jar and additionally, if not depending on thejersey-bundle.jar non-maven developers require:jersey-json.jar

11.4.4. Mail and MIME multipart

The use of the Java typejavax.mail.internet.MimeMultipart requires Java Mail version 1.4 or higher.

Maven developers require a dependency on thejava-mail module.

Non-maven developers require:

Jersey ships with a high-level MIME multipart API. Maven developers requires a dependency on thejersey-multipart module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.contribs</groupId>    <artifactId>jersey-multipart</artifactId>    <version>1.19.1</version></dependency>

Non-maven developers require:

11.4.5. Activation

The use of the Java typejavax.activation.DataSource requires no additional dependencies, as Java SE 6 ships everything needed.

11.5. Tools

By default WADL for resource classes is generated dynamically at runtime. WADL support requires a dependency on the JAXB reference implementation version 2.x or higher. Deploying an application for WADL support requires no additional dependences, since Java SE 6 ships with JAXB 2.x support.

The WADL ant task requires the same set of dependences as those for runtime WADL support.

11.6. Spring

Maven developers, using Spring 2.0.x or Spring 2.5.x, require a dependency on thejersey-spring module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.contribs</groupId>    <artifactId>jersey-spring</artifactId>    <version>1.19.1</version></dependency>

See the Java documentationhere on how to integrate Jersey-based Web applications with Spring.

11.7. Guice

Maven developers, using Guice 2.0, require a dependency on thejersey-guice module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.contribs</groupId>    <artifactId>jersey-guice</artifactId>    <version>1.19.1</version></dependency>

See the Java documentationhere on how to integrate Jersey-based Web applications with Guice.

The Jersey Guice support may also be used withGuiceyFruit, a set of extensions on top of Guice 2.0, such as support for Java EE artifacts like@PostConstruct/@PreDestroy,@Resource and@PersistenceContext. To avail of GuiceyFruit features exclude the guice dependency from the maven central repo and add the following:

<dependency>    <groupId>org.guiceyfruit</groupId>    <artifactId>guiceyfruit</artifactId>    <version>2.0</version></dependency>...<repository>    <id>guice-maven</id>    <name>guice maven</name>    <url>http://guiceyfruit.googlecode.com/svn/repo/releases/</url></repository>

11.8. Jersey Test Framework

NOTE that breaking changes have occurred between 1.1.1-ea and 1.1.2-ea. See the end of this section for details.

Jersey Test Framework allows you to test your RESTful Web Services on a wide range of containers. It supports light-weight containers such as Grizzly, Embedded GlassFish, and the Light Weight HTTP Server in addition to regular web containers such as GlassFish and Tomcat. Developers may plug in their own containers.

A developer may write tests using the Junit 4.x framework can extend from the abstractJerseyTest class.

Maven developers require a dependency on thejersey-test-framework-grizzly module. The following dependency needs to be added to the pom:

<dependency>    <groupId>com.sun.jersey.jersey-test-framework</groupId>    <artifactId>jersey-test-framework-grizzly</artifactId>    <version>1.19.1</version>    <scope>test</scope></dependency>

When utilizing an embedded container this framework can manage deployment and testing of your web services. However, the framework currently doesn't support instantiating and deploying on external containers.

The test framework provides the following test container factories:

  • com.sun.jersey.test.framework.spi.container.http.HTTPContainerFactory for testing with the Light Weight HTTP server.
  • com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory for testing in memory without using HTTP.
  • com.sun.jersey.test.framework.spi.container.grizzly.GrizzlyTestContainerFactory for testing with low-level Grizzly.
  • com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory for testing with Web-based Grizzly.
  • com.sun.jersey.test.framework.spi.container.grizzly2.GrizzlyTestContainerFactory for testing with low-level Grizzly2.
  • com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory for testing with Web-based Grizzly2.
  • com.sun.jersey.test.framework.spi.container.embedded.glassfish.EmbeddedGlassFishTestContainerFactory for testing with embedded GlassFish v3
  • com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory for testing with application deployed externally, for example to GlassFish or Tomcat.

The system propertyjersey.test.containerFactory is utilized to declare the default test container factory that shall be used for testing, the value of which is the fully qualified class name of a test container factory class. If the property is not declared then the GrizzlyWebTestContainerFactory is utilized as default test container factory.

To test a maven-based web project with an external container such as GlassFish, create the war file then deploy as follows (assuming that the pom file is set up for deployment):

mvn clean package -Dmaven.test.skip=true

Then execute the tests as follows:

mvn test \ -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.embedded.glassfish.external.ExternalTestContainerFactory \-DJERSEY_HTTP_PORT=<HTTP_PORT>

Breaking changes from 1.1.1-ea to 1.1.2-ea

The maven project groupId has changed fromcom.sun.jersey.test.framework tocom.sun.jersey

The extending of Jersey unit test and configuration has changed. Seehere for an example.

See the blog entry onJersey Test Framework for detailed instructions on how to use 1.1.1-ea version of the framework in your application.


Prev   Next
Chapter 10. Experimental Features Home Chapter 12. Jersey with GlassFish

[8]ページ先頭

©2009-2025 Movatter.jp