JarInputStream为现有的清单文件

时间:2017-01-06 21:50:32

标签: java jar manifest

使用JarInputStream获取(完全)操作.jar文件的Manifest时出现问题,我得到空指针。尝试了几个不同的文件,没有抛出异常。注意:此文件来自代码生成器。具有以下结构(希望这种形状有助于您理解它):

|[+]test.jar
  |[+]META-INF
      |MANIFEST.MF
  |[+]mypackage
      |MyClass.class
|text.txt

上面是类的一部分(注意:此类不在.jar中)

/*...code...**/
File jar = new File("resources/test.jar");
FileInputStream fis = new FileInputStream(jar);
JarInputStream jis = new JarInputStream(fis);
Manifest jarManifest = jis.getManifest();
Attributes jarManifestAttributes = jarManifest.getMainAttributes(); //line 25
String mainClass = jarManifestAttributes.getValue("Main-Class");
/*...code...**/

运行上面的代码时,抛出以下异常:

Exception in thread "main" java.lang.NullPointerException
at crypter.LoadJar.main(LoadJar.java:25)

所以jarManifest的值为null。

EDIT1 MANIFEST.MF

Manifest-Version: 1.0
Main-Class: mypackage.MyClass
Permissions: all-permissions

Name: text.txt

Name: mypackage/MyClass.class

EDIT2

jar -tvf reverse_tcp2.jar 
    37 Sat Jan 07 11:31:14 EET 2017 text.txt
     0 Sat Jan 07 11:31:14 EET 2017 mypackage/
  8513 Sat Jan 07 11:31:14 EET 2017 mypackage/MyClass.class
     0 Sat Jan 07 11:31:14 EET 2017 META-INF/
   145 Sat Jan 07 11:31:14 EET 2017 META-INF/MANIFEST.MF

0 个答案:

没有答案