开发者

getResourceAsStream works differently on Mac OSX vs. Windows 7?

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!开发者_如何学Go


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜