我必须从我的程序中的Manifest字段中读取信息。一切都很好。 但我想首先检查jar文件以确保存在清单。我怎样才能做到这一点?这就是我到目前为止所做的:
try {
InputStream inp = new FileInputStream(aJarLoc.toString());
JarInputStream jInp = new JarInputStream(inp);
Manifest manifest = jInp.getManifest(); //we need exception for missed manifest and for empty manifest!
Attributes attr = manifest.getMainAttributes();
} catch (Exception e) {
System.out.println("something goes wrong");
}
答案 0 :(得分:0)
如果没有清单,则在调用manifest.getMainAttributes()时会收到NullPointerException,这将在catch块中捕获。
您可能希望自己控制它并抛出更有意义的异常:
if ( manifest == null)
{
throw new Exception( "no manifest found in jar file " + aJarLoc);
}