wood burning stoves 2.0*
The moose likes Servlets and the fly likes Urgent: cannot find property file in war   when packaged in ear Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent: cannot find property file in war   when packaged in ear" Watch "Urgent: cannot find property file in war   when packaged in ear" New topic
Author

Urgent: cannot find property file in war when packaged in ear

Rashmi Tambe
Ranch Hand

Joined: Aug 07, 2001
Posts: 418
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?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
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?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
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.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
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
Hi,
i was able to find the reason, just wanted to share it..

as mentioned in J2EE API Specification, the function

getServletContext().getRealPath("/WEB-INF/eos.xml");

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 Here WEBlog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent: cannot find property file in war when packaged in ear
 
Similar Threads
JBOSS DeploymentException : Not able to find module file : .war in a .ear file
How to reference resources within EAR ?
reading a properties file
EAR not getting deployed with RAD 7.0 and Websphere 6.1
error delploying ear file on JBOSS 3.0.8