【发布时间】:2013-02-27 16:17:50
【问题描述】:
我尝试了多种方法来在单元测试中从正确的 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 以供单元测试使用?
【问题讨论】:
标签: java jar manifest.mf