Serving Static Content On WebLogic and GlassFish
Serving Static Content On WebLogic and GlassFish
2014
cdivilly
APPLICATIONEXPRESS,GLASSFISH,WEBLOGIC
ServingStaticContentonWebLogic
andGlassFish
POSTEDBYCDIVILLYJUNE21,2012
FILEDUNDER APPLICATIONEXPRESS,GLASSFISH,LISTENER,STATICCONTENT,
WEBLOGIC
BothOracleWebLogicandOracleGlassFishprovidemechanismstomixinstaticcontentlocatedoutside
aWebApplicationArchive(WAR).WecanleveragethesefacilitiestocreateasimpleWARthatcanbe
usedoneitherWebLogicorGlassFishforservingstaticcontent.
ThisprovidesaneasiertouseapproachforservingOracleApplicationExpressstaticresourceswhenusing
Oracle Application Express Listener, compared to zipping all the Application Express resources into a
largeWAR.Anaddedbenefitofthisapproachisthatchangeswithinthestaticresourcesfolderarepicked
upimmediately,noneedtorestartorupdatetheWAR.
Letsgetstarted,weregoingtocreateasmallWARthatcontainsthenecessarydeploymentdescriptors.
Firstcreateafoldertoworkin.
1
2
3
4
mkdirstatic
cdstatic
mkdirWEBINF
cdWEBINF
NowcreatetheJEEWARdescriptor,named:web.xmlwiththefollowingcontents:
1
2
3
4
5
<?xmlversion="1.0"encoding="UTF8"?>
<!DOCTYPEwebappPUBLIC
"//SunMicrosystems,Inc.//DTDWebApplication2.3//EN"
"http://java.sun.com/j2ee/dtds/webapp_2_3.dtd">
<webapp/>
<weblogicwebappxmlns="http://www.bea.com/ns/weblogic/weblogicw
<!Thiselementspecifiesthecontextpaththestaticresources
<contextroot>/i</contextroot>
<virtualdirectorymapping>
<!Thiselementspecifiesthelocationondiskwherethestati
<localpath>/path/to/apex/images</localpath>
<urlpattern>/*</urlpattern>
http://cdivilly.wordpress.com/2012/06/21/serving-static-content-on-weblogic-and-glassfish/
1/3
10.2.2014
8
9
</virtualdirectorymapping>
</weblogicwebapp>
Notethevaluesofthecontext-rootandlocal-pathelements,adjustthesevaluestomatchyour
requirements.
Next create the GlassFish specific deployment descriptor, named: sun-web.xml with the following
contents:
1
2
3
4
5
6
7
8
<?xmlversion="1.0"encoding="UTF8"?>
<!DOCTYPEsunwebappPUBLIC"//SunMicrosystems,Inc.//DTDGlass
<sunwebapp>
<!Thiselementspecifiesthecontextpaththestaticresources
<contextroot>/i</contextroot>
<!Thiselementspecifiesthelocationondiskwherethestatic
<propertyname="alternatedocroot_1"value="from=/*dir=/path/to/a
</sunwebapp>
Note the valuesofthe context-root element and the dir field within the value attribute of the
propertyelement,adjustthesevaluestomatchyourrequirements.
NextcreatetheWARfromthesefiles:
1
2
cd..
jarcvf../static.war.
Finallydeploythestatic.warfiletoyourWebLogicorGlassFishserver.
OnepointtonoteiswhenusingtheAdministrationUIinGlassFishtodeploytheWAR,thecontextroot
fieldisautofilledbytheUIbasedonthenameoftheWAR.Clearthecontentsofthisfieldtoensurethe
context-rootvaluespecifiedinthesun-web.xmlisused.
Abouttheseads
Discussion
Commentsareclosed.
cdivilly
BlogatWordPress.com.TheMorningAfterTheme.
Follow
http://cdivilly.wordpress.com/2012/06/21/serving-static-content-on-weblogic-and-glassfish/
2/3
10.2.2014
Followcdivilly
PoweredbyWordPress.com
http://cdivilly.wordpress.com/2012/06/21/serving-static-content-on-weblogic-and-glassfish/
3/3