Skip to main content

Deploying JAX-RS RESTful Web Services to the Oracle Cloud (Using JDeveloper and Jersey)

Posted by bleonard on April 30, 2013 at 1:28 PM PDT

In this blog entry I outline the steps necessary to deploy JAX-RS (JSR 311) RESTful web services to the Oracle Cloud. We'll be using Jersey, which is the reference implementation for JAX-RS, and JDeveloper, which is my primary Java IDE.

Step 1. Create a Jersey Library in JDeveloper

Download the latest version of jersey-bundle.jar, which at the time of this writing is version 1.17.1.

Start JDeveloper (the Oracle Cloud requires or

Select Tools > Manage Libraries and select New from the Manage Libraries dialog.

Set the Library Name to Jersey 1.17.1.

Add and Entry for jersey-bundle-1.17.1.jar

The completed dialog should look as follows:

Create Library

Click OK and then OK again to close the Manage Libraries dialog

Step 2: Create the Application

Create a new Generic Application named HelloJerseyApp:

With a project named HelloJerseyProj:

Step 3: Add the Jersey Library to the Project

Double-click the project name to open the Project Properties dialog. Select Libraries and Classpath and click Add Library. Select the Jersey 1.17.1 library that we just created.

While you are there, ensure the Java SE Version is set to 1.6, as this is the version the Java Cloud is using.

Step 4: Create a Java Class

Create a new Java Class named HelloJersey. The class will have two methods, one that returns text and another that returns JSON.

import com.sun.jersey.core.header.MediaTypes;

// The Java class will be hosted at the URI path "/hellojersey"
public class HelloJersey {
   // The Java method will process HTTP GET requests
   // The Java method will be hosted at the URI path "/hellojersey/text"
   // The Java method will produce content identified by the MIME Media
   // type "text/plan"
   public String getHelloWorldText() {
      return "Hello World";
   public String[] getHelloWorldJSON() {
      String[] helloWorld = {"Hello", "World"};
      return helloWorld;

Step 5: Configure Jersey Servlet in web.xml

In the editor you'll notice a Quick Fix to configure web.xml for Jersey JAX-RS web services:

Go ahead and implement the Quick Fix, which will create the web.xml.

Step 6: Create a WebLogic Deployment Descriptor

We will not be deploying the Jersey libraries with our application as they already exist in the Java Cloud. We just need to inform WebLogic that we want to use them.

Create a new WebLogic Deployment Descriptor, selecting weblogic.xml as the descriptor you wish to create:

Once created, select the Libraries and add JAX-RS as follows:

Step 7 (Optional): Make the Service Public

At this point we could deploy the application, but it would require your cloud credentials in order to view it. I'm going to make one minor addition to the web.xml which will make it available to the public. Simply add the empty <login-config/> tag to the file as shown below. You can read about the details of Updating web.xml in the Cloud Documentation.

Step 8: Create a Deployment Profile

Double-click the project name to open the Project Properties, select Deployment and click New to create a new Deployment Profile.

Set the Archive Type to WAR File and the name to HelloJersey:

On the Edit WAR Deployment Profile Properties page, Specify Java EE Web Context Root as HelloJersey:

Select Library Dependencies and deselect Jersey 1.17.1 under Libraries Selected for Deployment (remember we're going to use the libraries already available on the Java Cloud):

Step 9: Deploy the Project to the Oracle Cloud

For instructions on configuring JDeveloper to deploy to the Oracle Cloud, see Hello Oracle Cloud.

Right-click the project and select Deploy > HelloJersey.

Select Deploy to Application Server:

Select OracleCloud as the Application Server:

If there's an issue with deployment, look at the Oracle Cloud Job Log, which can be accessed from the Deployment - Log window:

Step 10: Use

The two services are now available for use:

In the URLs above, "HelloJersey" is the web context root (set in the WAR deployment profile), "jersey" is the URL pattern (set in web.xml), "hellojersey" is the URI path for the Java class (set in and "text" or "JSON" is the URI path for the Java method (also set in

HelloJerseyApp.zip19.73 KB