我正在尝试为 .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);
}
最佳答案
您需要在分号后添加空格作为前缀
改变
Class-Path:gson.jar
至
Class-Path: gson.jar
即 http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Name-Value_pairs_and_Sections
值:空格*otherchar换行符*继续
关于java - 如何创建jar文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22896967/