Perl:从 Java .jar 文件读取 MANIFEST.MF 文件
我试图弄清楚如何从 perl 中的 java jar 文件读取 META-INF/MANIFEST.MF 文件。我正在尝试使用 Mail::Header 来分隔中的属性清单。如果已经从 jar 中提取了清单文件,则效果很好,但我试图弄清楚如何将清单提取到内存中,然后立即放入 Header 对象中。这就是我到目前为止所拥有的:
my $jarFile = "MyJar.jar";
my &jar = Archive::Zip->new($jarFile);
my $manifest = Archive::Zip::MemberRead->new($jar, "META-INF/MANIFEST.MF");
my $header = Mail::Header->new;
$header->read(????);
print $header->get("Class-Path");
我无法弄清楚使用哪个构造函数和/或哪个提取/读取函数来读取 $manifest 文件句柄。 (我是 Perl 新手)
I'm trying to figure out how to read the META-INF/MANIFEST.MF file form a java jar file in perl. I'm attempting to use Mail::Header in order to separate the properties in the manifest. This works fine if the manifest file is already extracted from the jar, but I'm trying to figure out how to extract the manifest into memory and then immediately put into a Header object. This is what I have so far:
my $jarFile = "MyJar.jar";
my &jar = Archive::Zip->new($jarFile);
my $manifest = Archive::Zip::MemberRead->new($jar, "META-INF/MANIFEST.MF");
my $header = Mail::Header->new;
$header->read(????);
print $header->get("Class-Path");
I can't figure out which constructor and/or which extract/read function to use to read the $manifest file handle. (I'm new to perl)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MemberRead
有一个非常愚蠢的 API。它应该提供一个真实句柄,或者至少以兼容的方式模仿IO::File
(因此我们将其传递给Mail::Header
) > 构造函数或至少能够调用getlines
方法),但没有。我们可以通过将文件内容临时存储在数组中来解决它的不兼容性。
MemberRead
has a really dumb API. It should give a real handle, or at least mimicIO::File
in a compatible fashion (so we pass it to theMail::Header
constructor or at least be able to call thegetlines
method), but doesn't.We can work around its incompatibility by storing the file content temporarily in an array.