Urgent: cannot find property file in war when packaged in ear
Rashmi Tambe
Ranch Hand
Joined: Aug 07, 2001
Posts: 418
posted
0
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...
Rashmi Tambe
Ranch Hand
Joined: Aug 07, 2001
Posts: 418
posted
0
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.
Rashmi Tambe
Ranch Hand
Joined: Aug 07, 2001
Posts: 418
posted
0
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?
Kunaal A Trehan
Ranch Hand
Joined: Feb 04, 2004
Posts: 63
posted
0
Hi
Try this option. From the servlet get ServletContext object. Then use method getResourceAsStream("WEB-INF\folder-name\file-name") U will get the input stream for that file
Try this option.It shd work.
Rgds Kunal
Senthil B Kumar
Ranch Hand
Joined: Feb 09, 2004
Posts: 140
posted
0
Hi, i was able to find the reason, just wanted to share it..
as mentioned in J2EE API Specification, the function
will fail and return null when the resource is inside a war file...
so thatz why its failing in my case....
so i tried using
getServletContext().getResource() this has a new problem..
each time.. the application is access the WLS server extracts the ear to the wldonotdelete folder and creates folder each time the server is started and when the application is accessed first time.
so i cant give
getServletContext().getResource("/eos.xml")
because... when this xml is extracted.. its named as eosXXXXX.xml , where this XXXXX is some random number.. each time..
so is there anyother solution ??
Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside HereWEBlog
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Urgent: cannot find property file in war when packaged in ear