I have a set of unit test cases that depend on a test.properties file. When I run the tests under Mac OSX or Linux using Maven (‘mvn test’), they work fine. But when running under Windows 7, they can’t find the file unless I copy it directly to the class folder. The code to return the properties is the following two methods:
private void loadProperties() {
try {
properties.load(HibernateTestCase.class.getResourceAsStream(getPropertiesFilePath()));
} catch (Exception ioExc) {
ioExc.printStackTrace();
}
}
private String getPropertiesFilePath() {
return File.separator + "test.properties";
}
What’s the real deal here? Is it all about the file path being set wrong somewhere? Thanks in advance!
The separator in resource names is always ‘/’.
File.separatorvaries from platform to platform (on UNIX variants it will generally be/, on Windows it will not).