Resource Server Overlay Example

The recommended approach for using files from the Resource Server is via a WAR overlay in Maven. This allows you to includes the files in your final WAR without having to actually copy them into your project. It also ensures that the files are using the same path both locally and within the Resource Server, which is required to use the JSP tag library.

The following example includes jQuery 1.4.2 in the final WAR file and uses the JSP tag library to generate the link in the page. If the ResourceServingWebapp is deployed in the same container the tag library will generate a URL pointing to the ResourceServingWebapp. If the ResourceServingWebapp is not deployed the overlay ensures that the files are still available to the webapp and the tag library will generate a URL to the resource within the webapp.

In your <dependencies> section include:

<dependencies>
    <dependency>
        <groupId>org.jasig.resourceserver</groupId>
        <artifactId>resource-server-content</artifactId>
        <version>1.0.8</version>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>org.jasig.resourceserver</groupId>
        <artifactId>resource-server-utils</artifactId>
        <version>1.0.8</version>
    </dependency>
</dependencies>

In your <build> section include:

<plugins>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <webXml>${pom.basedir}/target/jspweb.xml</webXml>
            <overlays>
                <overlay>
                    <groupId>org.jasig.resourceserver</groupId>
                    <artifactId>resource-server-content</artifactId>
                    <includes>
                        <include>rs/jquery/1.4.2/</include>
                    </includes>
                </overlay>
            </overlays>
        </configuration>
    </plugin>
</plugins>

Substitute the appropriate paths for the resources you want to include in your project. When Maven builds your WAR file the resource server files will automatically be included.

If you are using Tomcat create a /META-INF/context.xml file in your web application with the following contents. This allows the resource server tag library to discover if the ResourceServingWebapp is deployed in the same container.

<Context crossContext="true"/>

In your JSP include the resources like:

<%@ taglib prefix="rs" uri="http://www.jasig.org/resource-server" %>

<rs:resourceURL var="jQueryPath" value="/rs/jquery/1.4.2/jquery-1.4.2.min.js"/>
<script type="text/javascript" language="javascript" src="${jQueryPath}"></script>