您的位置:首页 > 编程语言 > Java开发

用mac终端创建一个.jar文件(转载)

2016-04-14 23:54 423 查看
1) Ensure that all necessary files are within the directory, you have opened a terminal/Command Prompt and have navigated to that directory.

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

javac HelloWorld.java

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

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) Next create the JAR file using this code:

jar cfm HelloWorld.jar Manifest.txt HelloWorld.class

6) Run the file:

java -jar HelloWorld.jar

另外:如果你想要创建一个包含多个文件的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

followed by

jar cfm HelloWorld.jar Manifest.txt *.class

原文:

http://stackoverflow.com/questions/10125639/how-to-create-a-jar-file-using-the-terminal
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java mac 终端