如何创建jar文件?

时间:2014-04-06 16:46:59

标签: java jar

我正在尝试为.java程序创建一个jar文件

按照

步骤进行操作
Step 1. Create a 'mywork' folder
Step 2: Put the XYZ.java and the gson.jar file under the mywork folder
Step 3. Use javac -cp .:gson.jar XYZ.class
Step 4. Create Jar File -> jar cf XYZ.jar XYZ.class
Step 5. Create a Manifest.txt and modify it to include MainClass:XYZ
Step 6. Modify Manifest.txt to include classpath for gson.jar
Step 7. Then run the command-> jar cfm XYZ.jar Manifest.txt XYZ.class argument1 argument2

当我正在做第7步时,我正在

"java.io.IOException: invalid header field" error

我哪里出错,请帮我解决问题。

我的Manifest.txt就像

Manifest-Version: 1.0
Class-Path:gson.jar
Created-By: 1.7.0_06 (Oracle Corporation)
Main-Class: XYZ

主要方法:

public static void main(String[] args) throws Exception {

    // Enter the values for the arguments
    String dirstr = args[0];
    String logfiledirstr =  args[1];

        XYZ data = new XYZ();
        data.method1(dirstr,logfiledirstr);
}

2 个答案:

答案 0 :(得分:1)

清单文件末尾必须有“新行”。 给一个新行,然后检查。

您的文件必须是这样的:

Manifest-Version: 1.0
Class-Path: gson.jar
Created-By: 1.7.0_06 (Oracle Corporation)
Main-Class: XYZ (Press Enter)

答案 1 :(得分:1)

您需要在分号

后面加上空格前缀

更改

Class-Path:gson.jar

Class-Path: gson.jar

viz http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Name-Value_pairs_and_Sections

值:SPACE * otherchar换行符*延续

相关问题