Closed Thread Icon

Topic awaiting preservation: Setting path for properties file. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12953" title="Pages that link to Topic awaiting preservation: Setting path for properties file. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Setting path for properties file. <span class="small">(Page 1 of 1)</span>\

 
Pimms One
Bipolar (III) Inmate

From: Australia
Insane since: Jun 2003

posted posted 10-28-2003 00:51

Hi!

I am using Tomcat 4.1 with J2SDK 1.3.1_08. I have setup a context in
C:\1LMS\web-app

The LoadProperties.java file is located in:
C:/1LMS/web-app/WEB-INF/classes

and file.properties in
C:/1LMS/web-app/WEB-INF/classes/file.properties

My question is, how could I put the file.properties into say /WEB-INF/config
without having to specify the fullpath ('coz the instance name could change).

final String configFile= "/WEB-INF/config/file.properties";
does not seems to work.

Thank you.


-------LoadProperties.java----------------
import java.util.*;
import java.io.*;


public class LoadProperties {

static void displayValue() {

final String configFile = "C:/1LMS/web-app/WEB-INF/classes/file.properties";

Properties Prop = new Properties();

try {

FileInputStream configStream = new FileInputStream(configFile);

Prop.load(configStream);
configStream.close();

} catch(IOException e) {

System.out.println("Error: Cannot laod configuration file ");
}

final String PathImage =Prop.getProperty("ImagePath");
final String PathJsp = Prop.getProperty("JspPath");

System.out.println("ImagePath = " + PathImage);
System.out.println("JspPath = " + PathJsp);


} // displayValue


static public void main(String[] args) {

displayValue();

} // main

} // class

----------------------------------------

Rhino
Bipolar (III) Inmate

From: New Jersey, USA
Insane since: Jul 2003

posted posted 10-28-2003 10:27

My guess would be

final String configFile = "./config/file.properties";

You should need to specify the WEB-INF since you are already calling from inside that directory. You only need to back out of the Classes dir and the move on. Also, I would suggest that you don't hardcode the properties path inside the application. I would pass it in as one of the arguments withing the Main method. This would allow you more flexibility in the future without having to recompile.

« BackwardsOnwards »

Show Forum Drop Down Menu