我可以在java程序中读取所有类路径jar的MANIFEST文件。但是我想读MANIFEST文件的一个特定的jar说"xml-api -1.0.b2.jar"它怎么能做到?
我的工作代码是Enumeration resEnum;
try{
resEnum =Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
while (resEnum.hasMoreElements()) {
try {
URL url = (URL)resEnum.nextElement();
InputStream is = url.openStream();
if (is != null) {
Manifest manifest = new Manifest(is);
Attributes mainAttribs = manifest.getMainAttributes();
String vendor = mainAttribs.getValue("Implementation-Vendor");
String version = mainAttribs.getValue("Implementation-Version");
if(!mainAttribs.getValue("Extension-Name").equals("null")){
System.out.println(mainAttribs.getValue("Implementation-Title"));
System.out.println(version);
System.out.println(vendor);
System.out.println(mainAttribs.getValue("Extension-Name"));
}
}
}catch(Exception e){}
}
}catch(Exception e){
你可以试试这个
if (url.getFile().contains("xml-apis-1.0.b2.jar")) {
...
}
您必须使用JarFile类并使用getManifest()方法获取Manifest