File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes BEA/Weblogic and the fly likes FileNotFound error while reading a properties file using relative path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "FileNotFound error while reading a properties file using relative path" Watch "FileNotFound error while reading a properties file using relative path" New topic
Author

FileNotFound error while reading a properties file using relative path

Apu Shah
Greenhorn

Joined: Aug 15, 2004
Posts: 8
I am moving my tomcat application to weblogic. I have successfully deployed the war file as it is to the weblogic server.

I get FileNotFound Exception when running this application from Weblogic server. The problem is caused while opening the filestream with the relative path WEB-INF/app.properties. My servlets are jar-ed.

I have tried several combination of specifying the path. none of the following are working :
/app/WEB-INF/app.properties
../WEB-INF/app.properties
./app/WEB-INF/app.properties

Someone, please tell me what I need to change for this to be working?

thanks.
Ajay Reddy
Ranch Hand

Joined: Apr 08, 2005
Posts: 43
Try setting up the classpath of app.properties file in the startWeblogic.cmd file. In this startWeblogic.cmd file look for ---

'set CLASSPATH'.

Hope this helps.
Ajay Reddy
Ranch Hand

Joined: Apr 08, 2005
Posts: 43
If this does not work. Check where your code reads the property file location from.

I have created a directory called config. In this folder place your property file. This directory can be anywhere in your domain. But I have under bea8.1/user_projects/domain_name/config.

In your code when you like to lookup keys, read the values of the key.

String filePath = f.getAbsolutePath() + File.separator + "config" + File.separator + "application.properties";


FileReader read = new FileReader(new File(filename));
BufferedReader bRead = new BufferedReader(read);
String line = "";
boolean found = false;

while(((line = bRead.readLine()) != null) && (!found)) {
if (line.length() > newKey.length() + 1) {
if (((line.substring(0,newKey.length() + 1)).toUpperCase()).equals (newKey + "=")) {
s = line.substring(newKey.length()+1);
found = true;
}
}
}
read.close();

where newKey is key that you want to lookup the value.

KEY VALUE
---------------
SERVER=127.0.0.1

So the key is SERVER and the corresponding value=127.0.0.1

Hope this helps.
Debopam Poddar
Ranch Hand

Joined: Jun 21, 2005
Posts: 51

just change ur ntry in web.xml

put path /web-inf/....

hope this will solve ur problem
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I haven't tested this, but see if it works (to find the file app.properties and load it into a Properties object).


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileNotFound error while reading a properties file using relative path