Manifest.mf访问问题

时间:2016-04-11 15:55:25

标签: java jar manifest

我对build.xml(ANT)进行了更改,以添加有关作者,时间戳,版本的信息,并尝试从.mf文件访问相同的信息,但从新添加的Java代码中获取 null 值。

我期待Build-By,Build-Date和Build-Version的值在Manifest中。

当前输出

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.3.1_16-b06 (Sun Microsystems Inc.)
Built-By: null
Built-Date: null
Build-Version: null

的MANIFEST.MF:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_73-b02 (Oracle Corporation)
Built-By: mindpeace
Built-Date: 201604110952
Build-Version: 5.1

Java代码

try {
            mf.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/MANIFEST.MF"));
            Attributes atts = mf.getMainAttributes();
            System.out.println("Manifest-Version: " + atts.getValue("Manifest-Version"));
            System.out.println("Ant-Version: " + atts.getValue("Ant-Version"));
            System.out.println("Created-By: " + atts.getValue("Created-By"));
            System.out.println("Built-By: " + atts.getValue("Built-By"));
            System.out.println("Built-Date: " + atts.getValue("Built-Date"));
            System.out.println("Build-Version: " + atts.getValue("Build-Version"));

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

0 个答案:

没有答案