I have deployed my application in weblogic 8.1_sp5.The deployed application can be either in a .war file or .ear file format.This application loads a DOM object in to memory based on some settings in an xml file.The xml file is located on a particular path in the hard drive.
For eg :Let us assume the settings file is located in d:\myapplication\dist\myxml.xml. In general, we have a home path variable,based on which we get the location of the settings xml file.Let us assume the home path variable as APP_HOME. If the APP_HOME is set to d:\myapplication, we search for the \dist folder under that and locate the xml file. The application also has the option of getting the path from the source code, if APP_HOME is not set(It can be achieved in the following manner).
For eg: Let us say the jar file name is myapplication.jar(jar file that is available in the classpath). It contains a class named as MyUtils.class. Here we are making use of the class.getClassLoader()API (which returns a classLoader type) to get the name of the classLoader that loaded the above class into the JVM.
//The MyUtils.class code looks like this. ClassLoader cl=MyUtils.class.getClassLoader(); //now we are getting the URL for the above class by passing the path of MyUtils.class as //its argument. URL url=cl.getResource("com\myapp\MyUtils.class") String path=url.getFile();
This above string path is supposed to have a value like E: \myapplication \dist \lib \myapplib.jar! com\myapp\MyUtils.class once url.getFile() is invoked. From this, we truncate the path String and get the path for APP_HOME as e:\myapp\dist.
The problem is ...When we try like this in our application(.war or .ear file that is deployed in weblogic8.1_sp5), the url is returned as null.The .war or .ear file that is deployed is not able to locate the class file (available in the .jar file located in the classpath). As a result we are not able to set the value for home variable.