I am debugging in Eclipse and Tomcat - and I want to load in a property from a file called foo.properties. The file is stored in src directory, like so:
The following variable is always null:
java.net.URL url = loader.getResource(propFile);
which is becaue (I am guessing) the ClassLoader could locate the foo.properties file.
The properties file only has the text in it:
foo=bar
This is the full code I am using:
private static java.util.Properties prop = new java.util.Properties();
private static void loadProperties() {
// get class loader
ClassLoader loader = Config.class.getClassLoader();
if (loader == null)
loader = ClassLoader.getSystemClassLoader();
String propFile = "foo.properties";
java.net.URL url = loader.getResource(propFile);
try {
prop.load(url.openStream()); //ERROR HERE
} catch (Exception e) {
System.err.println("Could not load configuration file: " + propFile);
}
}
This is where I got the code snippet from source code
How do I get this file loaded properly?