以编程方式创建可运行的jar文件,主类清单问题

时间:2014-10-05 17:28:29

标签: java jar

我正在尝试创建一个可运行的jar文件但是我相信我遇到了清单问题。我在本网站上的另一篇文章中得到通知,即设置" Attributes.Name.MAIN_CLASS"清单文件的属性与runnable类的值将创建一个可运行的jar文件,在该文件启动时,该文件将运行您作为runnable文件输入的类值。不幸的是我的语法有点麻烦。以下是我现在正在尝试的内容:

String f = "LicenseFiller";
        String version = "1.0.0";
        String author = "concretepage";
        Manifest manifest = new Manifest();
        Attributes global = manifest.getMainAttributes();
        global.put(Attributes.Name.MANIFEST_VERSION, version);
        global.put(new Attributes.Name("Created-By"), author);
        global.put(Attributes.Name.MAIN_CLASS, f);

然而,没有错误消息,执行时程序将生成jar文件但不生成可运行的jar文件。当我在eclipse中创建runnable jar文件然后运行jar文件时,它完美地运行,因此LicenseFiller.class中没有任何内容导致问题。有人可以请更正我的语法吗?三江源。

更新:

当我反编译并检查我自己编译的jar到一个eclipse时。清单文件都包含与主类相同的值,但是eclipse使jar在runnable jar文件中有更多文件,但我相信这些只是多余的类,因为它们是由相同的默认包构成的。

我的罐子的清单:

Manifest-Version: 1.0.0
Created-By: concretepage
Main-Class: LicenseFiller

日食的显示:

Manifest-Version: 1.0
Class-Path: .
Main-Class: LicenseFiller

Name: org/jdom2/filter/
Specification-Title: JDOM Filter Classes
Implementation-Title: org.jdom2.filter
Implementation-Version: 2.0.5
Specification-Version: 2.0.0
Specification-Vendor: jdom.org
Implementation-Vendor: jdom.org

Name: org/jdom2/adapters/
Specification-Title: JDOM Adapter Classes
Implementation-Title: org.jdom2.adapters
Implementation-Version: 2.0.5
Specification-Version: 2.0.0
Specification-Vendor: jdom.org
Implementation-Vendor: jdom.org

Name: org/jdom2/
Specification-Title: JDOM Classes
Implementation-Title: org.jdom2
Implementation-Version: 2.0.5
Specification-Version: 2.0.0
Specification-Vendor: jdom.org
Implementation-Vendor: jdom.org

Name: org/jdom2/input/
Specification-Title: JDOM Input Classes
Implementation-Title: org.jdom2.input
Implementation-Version: 2.0.5
Specification-Version: 2.0.0
Specification-Vendor: jdom.org2
Implementation-Vendor: jdom.org

Name: org/jdom2/output/
Specification-Title: JDOM Output Classes
Implementation-Title: org.jdom2.output
Implementation-Version: 2.0.5
Specification-Version: 2.0.0
Specification-Vendor: jdom.org
Implementation-Vendor: jdom.org

Name: org/jdom2/transform/
Specification-Title: JDOM Transformation Classes

0 个答案:

没有答案