Hi,

Jay SenSharma

Jay SenSharma

Many times we all come across an issue where according to different environments in the production/QA/Testing/LAB we need to change the Properties files which is being used by the Application. And Properties file is placed inside the Application archive. We dont want to extract the archive EAR/WAR file to replace the Properties files to deployed in defferent environments. Sometimes in production Envs we want to make a small change in the properties file without any physical modification in the Actual Archieve…on the fly.

This Feature is also called as “Generic File Overloading using (AppFileOverrides) directory”.

WebLogic provides us this feature from WLS10.1 onwards to update an application’s static resources like Properties files/xml’s etc. Like following:

http://download-llnw.oracle.com/docs/cd/E15051_01/wls/docs103/notes/new.html#wp1068348

Step1).Directory Structure is very in order to achieve this…so better follow the exactly same directory structure…relatively to ur File Systems…

Create a Directory somewhere in your file system like following :
C:ResourceLoadingDemo

Step2). Create an EAR Application Directory “MyEAR” like following:

C:ResourceLoadingDemoMyEAR

Step3). Create the “META-INF” Directory for your EAR Application in following location:

C:ResourceLoadingDemoMyEARMETA-INF

Step4). Place the following “application.xml” file inside: “C:ResourceLoadingDemoMyEARMETA-INF”

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
<description>Split Directory Example</description>
<display-name>resource Loading Example</display-name>
<module>
<web>
<web-uri>ResourceWeb.war</web-uri>
<context-root>ResourceWeb</context-root>
</web>
</module>
</application>

Step5). Create “ResourceWeb” WAR application inside the MyEAR Application. Like following

C:ResourceLoadingDemoMyEARResourceWeb
NOTE: Once the ResourceWEB will be ready we will convert it into WAR file like: “ResourceWEB.war”

Step6). Provide the “index.jsp” file to read the Properties file in the following location: “C:ResourceLoadingDemoMyEARResourceWeb”

<%@ page import="java.util.*"%>
<h2> reading Property Files :
<%
Properties myAppProps = new Properties();
System.out.println("nnt ContextClassLoader : "+Thread.currentThread().getContextClassLoader());
InputStream iostream =Thread.currentThread().getContextClassLoader().getResourceAsStream("MyProps.properties");
System.out.println("nnt Got InputStream : "+iostream);

myAppProps.load(iostream);
out.println("<h2>keyOne : "+myAppProps.getProperty("keyOne"));
out.println("<h2>keyTwo : "+myAppProps.getProperty("keyTwo"));
out.println("<h2>keyThree : "+myAppProps.getProperty("keyThree"));
%>

Step7). Create a Properties  “MyProps.properties” in the following Location: “C:ResourceLoadingDemoMyEARResourceWEB-INFclasses”  Like following key-value pairs:

keyOne=ValueOfKeyOne
keyTwo=ValueOfKeyTwo
keyThree=ValueOfKeyThree

Step8). Provide a default “web.xml” in the following Location : “C:ResourceLoadingDemoMyEARResourceWEB-INF”

<!DOCTYPE web-app PUBLIC  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>

You must provide at least one default “weblogic.xml” file … with some contents inside it or Just a Default …like following:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
</weblogic-web-app>

Step9). Open a command prompt and then run “. ./setWLSEnv.sh” or “setWLSEnv.cmd” and then nevigate to the directory:

“C:ResourceLoadingDemoMyEARResourceWeb” to create a WAR file:

C:ResourceLoadingDemoMyEARResourceWeb>jar cvf ResourceWeb.war .
added manifest
adding: index.jsp(in = 697) (out= 298)(deflated 57%)
adding: WEB-INF/(in = 0) (out= 0)(stogreen 0%)
adding: WEB-INF/classes/(in = 0) (out= 0)(stogreen 0%)
adding: WEB-INF/classes/MyProps.properties(in = 68) (out= 39)(deflated 42%)
adding: WEB-INF/lib/(in = 0) (out= 0)(stogreen 0%)
adding: WEB-INF/web.xml(in = 157) (out= 133)(deflated 15%)

Step10). Cut the “ResourceWeb.war” file from “C:ResourceLoadingDemoMyEARResourceWeb” and Paste it inside : “C:ResourceLoadingDemoMyEAR” Location.

Step11). Delete the “ResourceWeb”  Directory present inside “C:ResourceLoadingDemoMyEAR”.

Step12). Deploy “MyEAR” application present in “C:ResourceLoadingDemo” location on the WebLogic Server.

Step13). Access the “index.jsp” Page to see if we are able to access the Properties file data or not:

http://localhost:7001/ResourceWeb/index.jsp

Step14). Now in order to overtide the Properties file present inside the ResourceWeb.war file we need to create a Directory “plan” Just beside “MyEAR” inside the following Location “C:ResourceLoadingDemo”

Step15). Create “plan.xml” file like following present in the following location: “C:ResourceLoadingDemoplan”

To create Plan.xml Just Change the Session-Invalidation interval from Admin Console…it will create the following “Plan.xml” or u can use any existing file as well. Location of this file must be “C:ResourceLoadingDemoplan”

<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-deployment-plan.xsd">
<application-name>ResourceLoadingDemo</application-name>

<variable-definition>
<variable>
<name>SessionDescriptor_invalidationIntervalSecs_12752869244060</name>
<value>61</value>
</variable>
</variable-definition>

<module-override>
<module-name>MyEAR</module-name>
<module-type>ear</module-type>
<module-descriptor external="true">
<root-element>weblogic-application</root-element>
<uri>META-INF/weblogic-application.xml</uri>
</module-descriptor>
<module-descriptor external="false">
<root-element>application</root-element>
<uri>META-INF/application.xml</uri>
</module-descriptor>
</module-override>

<module-override>
<module-name>ResourceWeb</module-name>
<module-type>war</module-type>
<module-descriptor external="false">
<root-element>weblogic-web-app</root-element>
<uri>WEB-INF/weblogic.xml</uri>
<variable-assignment>
<name>SessionDescriptor_invalidationIntervalSecs_12752869244060</name>
<xpath>/weblogic-web-app/session-descriptor/invalidation-interval-secs</xpath>
</variable-assignment>
</module-descriptor>
<module-descriptor external="false">
<root-element>web-app</root-element>
<uri>WEB-INF/web.xml</uri>
</module-descriptor>
</module-override>

<config-root>C:ResourceLoadingDemoplan</config-root>
</deployment-plan>

Step15-A). Create a Directory Tree like following:

“C:ResourceLoadingDemoplanAppFileOverridesResourceWeb.war”

Note:  “ResourceWeb.war” in the above path is a Directory and not a File.

Step16). To Override the Property file , Please Provide a new Property file “MyProps.properties” inside “C:ResourceLoadingDemoplanAppFileOverridesResourceWeb.war” directory. With New Values…

keyOne=<font color=green>ValueOfKeyOneCHANGED_A</font>
keyTwo=<font color=green>ValueOfKeyTwoCHANGED_B</font>
keyThree=<font color=green>ValueOfKeyThreeCHANGED_C</font>

Step17). Login to WebLogic Admin Console and then Click Lock&Edit Button —>Select your Application…(MyEAR)—>Update

Step18).Once u Activate the changes from Admin Console…Now refresh the Browser…

.

.

Thanks

Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.