我创建了一个 eclipse 插件项目和一个用于 junit 测试的相应片段项目。
在片段中,我将插件项目指定为“主机插件”。此外,我在 build.properties 窗格中指定以下内容:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
my.properties
其中 my.properties 是位于片段项目根目录的文件。然后我编写了一个测试,尝试像这样加载 my.properties 文件:
Properties properties = new Properties();
InputStream istream = this.getClass().getClassLoader()
.getResourceAsStream("my.properties");
try {
properties.load(istream);
} catch (IOException e) {
e.printStackTrace();
}
但是istream
是 null 并且在 try 块中调用 load 时测试失败并出现 NullPointerException。
我试图在主机插件中做同样的事情,它工作正常。关于为什么我在使用 Junit 时无法读取 PDE 片段中的资源的任何想法?