Packaging a JAX-RS application

Applications utilizing the IBM JAX-RS runtime can be packaged using a provided ant script. The buildWar.xml is included in the distribution under the ${IBM_JAXRS_HOME}/resources directory. Optionally, if using a WebSphere Application Server stand-alone configuration, the ant script can be invoked to include installing the packaged WAR.

  1. Copy the buildWar.xml provided in the IBM JAX-RS distributables to the root level of the project.

    If you are using Eclipse, you can import the build script using by right-clicking on the project folder and going to "Import...". On the next panel select "File System" as the input type and click "Next". Browse to the resources directory within your IBM JAX-RS distribution folder and import the buildWar.xml file.

    If you are using a command-line environment, you can simply copy the buildWar.xml from the distribution folder to the root of your development folder.


  2. Edit the project specific properties in the build script.

    There are four properties that must be modified in the buildWar.xml

    Table 1. Properties Overview
    Property Description
    build.dir The directory that contains the compiled .class files for the project. These .class files will be put into the WEB-INF/classes directory of the created WAR.
    ibm.jaxrs.home The directory that contains the expanded IBM JAX-RS distributables.
    application.class The javax.ws.rs.core.Application subclass that is provided by the application.
    war.name The name of the WAR that is created.

    When utilizing the script to install to a WebSphere Application Server configuration, there are two additional properties that must be supplied

    Table 2. Properties Overview
    Property Description
    profile.root The path to the WebSphere Application Server profile for your configuration.
    context.root The context root to which the WAR will be deployed.

    Consider the case where the project has the following property values:

    • build.dir - /usr/projects/jaxrs/build/classes
    • ibm.jaxrs.home - /usr/downloads/IBM/jaxrs
    • application.class - sample.jaxrs.Application
    • war.name - jaxrsSample.war
    • context.root - /rest
    • profile.root - /opt/user/was/profiles/AppSrv01

    The build.xml would be updated as follows:

    
    <!-- The value of this property should be the path to a directory
    	containing the build outputs of your project. -->
    <property name="build.dir" value="/usr/projects/jaxrs/build/classes" />
    
    <!-- The value of this property is the path that will be used to
    	store the generated web.xml for your application. This directory
    	will be removed by the build file.-->
    <property name="tmp.dd.dir" value="ibmjaxrs_tmp_dd_output" />
    
    <!-- The value of this property points to the location of the generated
    	web.xml. It should not be changed -->
    <property name="webxml.path" value="${tmp.dd.dir}/web.xml" />
    
    <!-- This points to the location of the IBM JAX-RS distributables. -->
    <property name="ibm.jaxrs.home" value="/usr/downloads/IBM/jaxrs" />
    
    <!-- The value of this property is the application-provided javax.ws.rs.core.Application subclass. -->
    <property name="application.class" value="sample.jaxrs.Application" />
    
    <!-- The value of this property will be the name of the created WAR. -->
    <property name="war.name" value="jaxrsSample.war" />
    
    <!-- Name of the context root the WAR will be deployed with in WAS. Only needed for 'installToWAS' target -->
    <property name="context.root" value="/rest" />
    
    <!-- Path of WAS profile the WAR will be installed under. Only needed for 'installToWAS' target -->
    <property name="profile.root" value="/opt/user/was/profiles/AppSrv01" />
    


  3. If you do not intend to install the packaged WAR to a WebSphere Application Server configuration, simply run the "ant" command after the preceding properties have been set. A WAR with the supplied name will be created in the same directory of the buildWar.xml file.

    If you do intend to install the packaged WAR to a WebSphere Application Server configuration, run the "ant installToWAS" command after the preceding properties have been set. A WAR with the supplied name will be created in the same directory of the buildWar.xml file, and the WAR will be installed to the indicated WebSphere Application Server configuration.

    The script can also be run from within Eclipse by right-clicking on the buildWar.xml and click Run As > Ant Build.