我尝试了多种方法来在单元测试中从正确的 jar 访问清单。我遇到的问题是它似乎是在读取它的第一个 jar 文件,而不是我班级的那个。这是我最近的尝试
InputStream is = Test.class.getResourceAsStream("/META-INF/MANIFEST.MF");
try {
if (is == null) {
System.out.println("null no input stream");
} else {
Manifest manifest = new Manifest(is);
Attributes attributes = manifest.getMainAttributes();
v = attributes.getValue("Test");
System.out.println("Test="+v);
v = attributes.getValue("Created-by");
System.out.println("By="+v);
}
} catch (IOException e) {
System.out.println("error");
} finally {
if (is != null) {
is.close();
}
}
这些是结果
Test=null
By=1.6.0_18 (Sun Microsystems Inc.)
MANIFEST.MF
我想使用的值为,Test
所以我知道这是读取错误的文件
有谁知道我如何指定包含清单文件以供单元测试使用的 jar?