File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileNotFound error while reading a properties file using relative path

 
Apu Shah
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
Eclipse IDE Java jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just change ur ntry in web.xml

put path /web-inf/....

hope this will solve ur problem
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tested this, but see if it works (to find the file app.properties and load it into a Properties object).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic