如何使用终端创建.jar文件 [英] How to create a .jar file using the terminal

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

问题描述

我正在尝试使用mac终端创建一个.jar文件但是有点麻烦。我按照这里的步骤进行了操作,但未成功。我收到此错误消息:

I'm trying to create a .jar file using the mac terminal but am having bit of trouble. I followed the steps here but was unsuccessful. I got this error message:

Failed to load Main-Class manifest attribute from
aclient.jar

那你究竟是怎么做的呢?我的java程序叫做Main.java,我把它编译成.class文件。现在该怎么办?

So how exactly do you go about doing it? My java program is called Main.java and I have compiled it into a .class file. Now what do I do?

谢谢

推荐答案

1)确保所有必需的文件都在目录中,你已经打开了一个终端/命令提示符并导航到该目录。

1) Ensure that all necessary files are within the directory, you have opened a terminal/Command Prompt and have navigated to that directory.

2)编译.java类,例如HelloWorld .java with

2) Compile the .java class, for example HelloWorld.java with

javac HelloWorld.java

3)这将产生JAR文件所需的.class文件。

3) This will produce a .class file needed for the JAR file.

4)接下来创建一个清单文件(使用扩展名.txt)使用文本编辑器并输入以下内容

4) Next create a manifest file (saved using the extension .txt) using the text editor and input the following

Main-Class: HelloWorld

或者你的文件名是什么。

or whatever your file's name is.

5)接下来创建JAR文件使用此代码:

5) Next create the JAR file using this code:

jar cfm HelloWorld.jar Manifest.txt HelloWorld.class

6)运行文件:

java -jar HelloWorld.jar

若有看见ms不清楚请参考这些网站:
创建一个jar文件设置应用程序入口点

If anything seems unclear consult these websites: creating a jar file and setting an applications entry point.

希望这有助于其他人,为汤姆喝彩!

Hope this helps others, cheers Tom!

编辑:

在inga的评论之后,值得注意的是,为了在jar中包含多个文件,您需要使用:

Following inga's comment it's worth noting that in order to include multiple files in the jar you need to use the:

javac *.java

后跟

jar cfm HelloWorld.jar Manifest.txt *.class

这篇关于如何使用终端创建.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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