views:

128

answers:

2

Hi all,

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!

A: 

Either your classpath is different, or you're using a different classloader with different resolution characteristics.

Jim Garrison
+2  A: 

The separator in resource names is always '/'. File.separator varies from platform to platform (on UNIX variants it will generally be /, on Windows it will not).

Tom Hawtin - tackline
Replacing the last line in my code from File.separator + "test.properties" to just "/test.properties" filled the bill. Thanks!
Tom H