//
Application Express, GlassFish, WebLogic

Serving Static Content on WebLogic and GlassFish

Both Oracle WebLogic and Oracle GlassFish provide mechanisms to mix-in static content located outside a Web Application Archive (WAR). We can leverage these facilities to create a simple WAR that can be used on either WebLogic or GlassFish for serving static content.

This provides an easier to use approach for serving Oracle Application Express static resources when using Oracle Application Express Listener, compared to zipping all the Application Express resources into a large WAR. An added benefit of this approach is that changes within the static resources folder are picked up immediately, no need to restart or update the WAR.

Let’s get started, we’re going to create a small WAR that contains the necessary deployment descriptors. First create a folder to work in.

mkdir static
cd static
mkdir WEB-INF
cd WEB-INF

Now create the JEE WAR descriptor, named: web.xml with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app/>

Next create the WebLogic specific deployment descriptor, named: weblogic.xml with the following contents:

<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
 <!-- This element specifies the context path the static resources are served from -->
 <context-root>/i</context-root>
 <virtual-directory-mapping>
  <!-- This element specifies the location on disk where the static resources are located -->
  <local-path>/path/to/apex/images</local-path>
  <url-pattern>/*</url-pattern>
 </virtual-directory-mapping>
</weblogic-web-app>

Note the values of the context-root and local-path elements, adjust these values to match your requirements.

Next create the GlassFish specific deployment descriptor, named: sun-web.xml with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app>
 <!-- This element specifies the context path the static resources are served from --> 
 <context-root>/i</context-root>
 <!-- This element specifies the location on disk where the static resources are located -->
 <property name="alternatedocroot_1" value="from=/* dir=/path/to/apex/images"/>
</sun-web-app>

Note the values of the context-root element and the dir field within the value attribute of the property element, adjust these values to match your requirements.

Next create the WAR from these files:

cd ..
jar cvf ../static.war .

Finally deploy the static.war file to your WebLogic or GlassFish server.

One point to note is when using the Administration UI in GlassFish to deploy the WAR, the context root field is auto-filled by the UI based on the name of the WAR. Clear the contents of this field to ensure the context-root value specified in the sun-web.xml is used.

About these ads

Discussion

Comments are closed.

Twitter

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.

Archives

Follow

Get every new post delivered to your Inbox.

Join 93 other followers