Hi all, I have a war file packaged within an ear file. When I try to read a property file in a servlet using ResourceBundle, I get an exception as the property file cannot be found. However, when i deploy the same war alone (w/o packaging it as ear), the war classloader can find the property file and load properties. The property file is placed under WEB-INF/classes folder. And I am using weblogic 7.0.2 app server.
Why can't ear classloader find this file? what can i do to solve this problem? Can anybody help please?
well no, the EAR classloader won't be able to see a property in the WAR JAR file. Are you sure you need to load the property in the EAR, or can you limit it to the WAR?
There may be something I'm missing here...
Joined: Aug 07, 2001
yeah I have to load the property file some how so that the servlet can read it. Now when I simply doploy the war, war classloader can locate the file in web-inf/claases directory. However, when the war is packaged along with some server side componenets in an ear, then the ear classloader does not delegate this task to war classloader and it itself cannot locate the file web-inf/classes directory.
Now, do i have to set some class path or lib path in the appliocations.xml in the ear so ear classloader can find it? Or is there any other way out?
Does the EAR need to load the properties? If only the WAR needs them then leave the WAR ClassLoader loading the classes. There are ways to get the EAR assing the WAR ClassLoader and thereby making the properties available at the EAR level, but better not to if you don't have to.
Joined: Aug 07, 2001
Originally posted by David O'Meara: Does the EAR need to load the properties? If only the WAR needs them then leave the WAR ClassLoader loading the classes. There are ways to get the EAR assing the WAR ClassLoader and thereby making the properties available at the EAR level, but better not to if you don't have to.
thanks for the reply David. however, i am still not clear. The war needs the property file and not ear. The file is at WAR level (web-inf/classes directory). and it is not needed to access it at ear level. Now, i dont know, which classloader fails to access it when i package the war into an ear.
How are you loading the properties file? Are you sure you're using the correct ClassLoader? As a bit of a cheat, I tend to use a Class that is attached to the WAR to find the WAR ClassLoader and then the properties file. eg if MyServlet is packaged in the WAR, use MyServlet.class.getClassLoader().getResource(...etc...) (of course this can also be reduced to class.getResource(...))
You may find that the problem was in the way you were trying to specify a ClassLoader. Does this sound possible, or am I on the wrong track?