On 2008-11-18 07:52:47 +0100,
said:
> How do I make sure my application loads the settings file regardless
> of where it is? I thought of passing the database settings file to a
> constructor of a database settings dialog class. But I don’t know how
> to sort out the path issue.
One possible approach might be to use the classloader for locating the
file. Eg. you have a jar with the following contents
- META-INF
- com
- yourproject
- dbsettings.properties
Put this jar file into the classpath of your application. Then you can
use the following code to look it up:
public static void main(String args[]) {
InputStream is =
MySuperFrame.class.getRessourceAsStream("/dbsettings.properties");
Properties p = new Properties();
p.load(is);
// now p contains all your settings
}
This should work regardless of the actual location of the properties
file, as long as it is in your classpath. You can put it inside a jar
or even put it plain into a folder, as long as you put that folder into
your classpath.
Hope that helps.
Best regards,
Jan