Links: Table of Contents | Single HTML

Chapter 12. Jersey with GlassFish

Table of Contents

12.1. Overriding Jersey with war files
12.2. Upgrading Jersey in GlassFish
12.2.1. GlassFish v3.0 and 3.0.1
12.2.2. GlassFish 3.1

This chapter will present instructions on how to use Jersey with Glassfish when Jersey is distributed in the war and to manually upgrade the Jersey version bundled with a GlassFish installation.

12.1. Overriding Jersey with war files

To override the version of Jersey distributed in GlassFish with a version of Jersey distributed in a war file ensure that class loader delegation is set to false in WEB-INF/sun-web.xml or WEB-INF/glassfish-web.xml. For example:

<sun-web-app error-url="">
    <context-root>/context</context-root>
    <class-loader delegate="false"/>
</sun-web-app>

In the GlassFish admin console, go to Configuration->JVM Settings, switch to the JVM Options tab and add the following option:

-Dcom.sun.enterprise.overrideablejavaxpackages=javax.ws.rs,javax.ws.rs.core,javax.ws.rs.ext

Restart GlassFish for new JVM settings to take effect.

12.2. Upgrading Jersey in GlassFish

12.2.1. GlassFish v3.0 and 3.0.1

GlassFish v3.0 comes up with Jersey version 1.1.4.1. GlassFish v3.0.1 with Jersey version 1.1.5. To upgrade these to 1.19.1 you will need to replace certain files manually.

GlassFish uses Jersey internally in it's REST administration API, and the Update Center client would not allow you to upgrade in order to prevent this functionality. The workaround described in this section is known to work, but it is not currently a tested and supported scenario. Please keep in mind things could break. It is recommended to back up all all impacted files. The actual replace steps follow.

Remove the existing Jersey files: Stop all running server instances. Then remove the following files from the GlassFish installation directory:

  • glassfish/modules/jsr311-api.jar
  • glassfish/modules/jersey-gf-bundle.jar
  • glassfish/modules/jersey-gf-statsproviders.jar
  • glassfish/modules/jersey-multipart.jar
  • glassfish/modules/jackson-core-asl.jar
  • glassfish/modules/jettison.jar
  • glassfish/modules/mimepull.jar

Download the new Jersey version archive from https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.glassfish.v3&a=jersey-gfv3-core&v=1.19.1&c=project&e=zip and unzip it's glassfish/modules content into the GlassFish installation directory (to the glassfish/modules subdirectory there).

To install also Jersey examples in addition, download https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.glassfish.v3&a=jersey-gfv3-docs-and-samples&v=1.19.1&c=project&e=zip and unzip it's content into the GlassFish installation directory.

To be 100 % sure the changes take effect, you might also want to remove the felix cache, which is located in glassfish/domains/domain1/osgi-cache directory. This directory gets created upon the first start of the GlassFish instance.

12.2.2. GlassFish 3.1

GlassFish 3.1 is released. GlassFish 3.1 builds can be downloaded from http://glassfish.java.net/downloads/3.1-final.html

If you want to update the Jersey bits in GlassFish with the latest Jersey snapshot version, or if you want to install Jersey documentation and examples, you would need to do the following steps:

Remove the existing Jersey files: Stop all running server instances. Then remove the following files from the GlassFish installation directory:

  • glassfish/modules/jersey-core.jar
  • glassfish/modules/jersey-client.jar
  • glassfish/modules/jersey-gf-server.jar
  • glassfish/modules/jersey-json.jar
  • glassfish/modules/jersey-multipart.jar
  • glassfish/modules/jersey-gf-statsproviders.jar
  • glassfish/modules/jackson-core-asl.jar
  • glassfish/modules/jackson-mapper-asl.jar
  • glassfish/modules/jackson-jaxrs.jar
  • glassfish/modules/jettison.jar

Download the new Jersey version archive from https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.glassfish.v3&a=jersey-gfv3-core&v=1.19.1&c=project&e=zip and unzip it's glassfish/modules content into the GlassFish installation directory (to the glassfish/modules subdirectory there).

To install also Jersey examples in addition, download (you can change the version in the link to get another non-snapshot version of Jersey) https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey.glassfish.v3&a=jersey-gfv3-docs-and-samples&v=1.19.1&c=project&e=zip and unzip it's content into the GlassFish installation directory.

To be 100 % sure the changes take effect, you might also want to remove the felix cache, which is located in glassfish/domains/domain1/osgi-cache directory. This directory gets created upon the first start of the GlassFish instance.