I have a project CouponSystem which have a config/cs.properties file. This project exported as cs.jar and added to another project which exporting a web-app csee.war
when the CouponSystem runs (as java application) it loads the Utils class that reads config/cs.properties correctly .
when the csee runs on server (tomcat7) i cannot find that file. after creating some method to understand where the tomcat looks for that file, i realize that its looking on the tomcat/bin directory - so if i put the file in tomcat/bin/cs.properties : everything works . ( not a solution, just to understand the problem)
my question is - where is the correct way to put the cs.properties in a web-app environment , and how to tell a non servlet class (Utils) to find it ?
Thanks .
public class Utils {
public static final String CONFIG_FILE = "cs.properties";
//public static final String CONFIG_FILE = "WEB-INF/config/cs.properties";
// builds a hashmap from properties file
public static void loadSystemParameters() {
// this code only to know "the default current dir"
File f = new File("."); // current directory
File[] files = f.listFiles();
for (File file : files) {
if (file.isDirectory()) {
System.out.print("directory:");
} else {
System.out.print(" file:");
}
try {
System.out.println(file.getCanonicalPath());
} catch (IOException e) {
e.printStackTrace();
}
}
Utils.logMessage(new Utils(), Severity.DEBUG, "loadSystemParameters() invoked");
// construct a List<Customer> to return the data
sysParams = new HashMap<String, String>();
Properties properties = new Properties();
try {
properties.load(new FileReader(CONFIG_FILE));
for(String propName : properties.stringPropertyNames()){
sysParams.put(propName, properties.getProperty(propName));
}
Utils.logMessage(new Utils(), Severity.DEBUG, "properties from file loaded to a hashmap");
} catch (IOException e) {
Utils.logMessage(new Utils(), Severity.ERROR, "cannot load properties file ! exiting.");
e.printStackTrace();
//System.exit(0);
}
}
}