[英]How to get Manifest.mf file content from a jar file
I have a jar file named " mail.jar " .I have extracted the jar file through java code.我有一个名为“ mail.jar ”的 jar 文件。我已经通过 java 代码提取了 jar 文件。 Now I have manifest file present under "D:/Test/META-INF/MANIFEST.MF" location.
现在我在“D:/Test/META-INF/MANIFEST.MF”位置下有清单文件。 This is the image of Manifest.mf file content .
这是 Manifest.mf 文件内容的图像。 Any way I am able to read to Manifest file by the help of FileReader and BufferedReader and print it to the console.
我可以通过FileReader和BufferedReader的帮助读取清单文件并将其打印到控制台的任何方式。 In the manifest file ,below specifications r present.
在清单文件中,存在以下规格。 (1)Manifest-Version: (2)Archiver-Version: (3)Created-By: (4) Export-Package:
(1)Manifest-Version: (2)Archiver-Version: (3)Created-By: (4) Export-Package:
Now my doubt is how to get all the package list under Export-Package: tag only .现在我的疑问是如何获取Export-Package: tag only 下的所有包列表。 Can anyone help me here ??
有人能帮我一下吗 ?? Any help will be appreciated.
任何帮助将不胜感激。
O/P should display like below screen shot. O/P 应显示如下屏幕截图。 Expected O/P screen shot
预期的 O/P 屏幕截图
Regards, AD问候, 广告
Hi solomon & PeterMmm, Thanks for your help.嗨所罗门和 PeterMmm,感谢您的帮助。 now I am able to access the manifest file content for specific attribute.
现在我可以访问特定属性的清单文件内容。 Below is the code snippet I am using:-
以下是我正在使用的代码片段:-
public class ReadmanifestFile {
public String getManifestAttributes() throws IOException {
String value = null;
File file = new File("G:/AD/JAR_FILES/mail.jar");
if (file.isFile()) {
JarFile jarfile = new JarFile(file);
Manifest manifest = jarfile.getManifest();
Attributes attributes = manifest.getMainAttributes();
value = attributes.getValue("Export-Package");
String[] arr = value.split(";");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
return value;
}
} }
click the below for Output for above code snippet:- Output单击下面的输出以获取上述代码片段:-输出
I think this is right way to do.Plz let me know if I can improve the code snippet in any of the other ways.我认为这是正确的方法。请让我知道我是否可以通过任何其他方式改进代码片段。
regards, AD问候,广告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.