Java创建.jar文件 [英] Java creating .jar file

查看:75
本文介绍了Java创建.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java,但我遇到了问题。我创建了6个不同的类,每个类都有自己的 main()方法。我想为每个类创建可执行文件 .jar ,即6个可执行文件 .jar 文件。

I'm learning Java and I have a problem. I created 6 different classes, each has it's own main() method. I want to create executable .jar for each class, that is 6 executable .jar files.

到目前为止,我试过

java -jar cf myJar.jar myClass.class

我得'无法访问jarfile cf'。我做错了什么,但我不知道是什么。我也使用Eclipse IDE,如果这意味着什么。

and I get 'Unable to access jarfile cf'. I'm doing something wrong but I don't know what. I'm also using Eclipse IDE if that means something.

推荐答案

为了创建.jar文件,你需要使用 jar 而不是 java

In order to create a .jar file, you need to use jar instead of java:

jar cf myJar.jar myClass.class

此外,如果你想做它可执行文件,您需要为您的应用程序指明入口点(即,带有 public static void main(String [] args)的类)。这通常是通过创建包含<的清单文件来完成的。 code> Main-Class 标题(例如, Main-Class:myClass )。

Additionally, if you want to make it executable, you need to indicate an entry point (i.e., a class with public static void main(String[] args)) for your application. This is usually accomplished by creating a manifest file that contains the Main-Class header (e.g., Main-Class: myClass).

但是,正如Mark Peters指出的那样,使用JDK 6,您可以使用 e 选项来定义条目point:

However, as Mark Peters pointed out, with JDK 6, you can use the e option to define the entry point:

jar cfe myJar.jar myClass myClass.class 

最后,你可以执行它:

java -jar myJar.jar



参见



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆