java - 如何创建jar文件?

标签 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);
}

最佳答案

您需要在分号后添加空格作为前缀

改变

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/

相关文章:

java - 在java中将String类型的二进制数转换为位

java - JVM 时间同步选项

Java:为什么打包成jar文件的代码会阻止外部类访问?

java - 创建没有依赖的jar A,并让依赖项目C下载这个依赖A所依赖的依赖B

java - Spring 组件扫描嵌套 jar

Java:更喜欢取决于类实例或静态方法的实用程序类?

java - 安卓混合模式

java - 在 Java 中对 Web-http 响应进行数字签名(使用 pgp)

Java .jar 不在 Windows 上运行

java - 使用 JAR 导出图像/文本文件