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

Eclipse导出jar文件以及JAR File和Runnable JAR File的区别

2017-07-19 21:24 302 查看
现在我写好了一个java项目,想要导出可执行的jar文件。有两种方法,具体如下。

I. Runnable JAR File

点击Eclipse左上角的“File”按钮,选择“Export”。

选择Java下的“Runnable JAR File”,点击“Next”。



直接”Finish”。



II. JAR File

File>Export。

选择Java下的“JAR File”,点击“Next”。



点击“Next”。



点击“Next”。



选择main函数的所在文件,点击”Finish”。



如何执行JAR?

在命令行通过java -jar <文件名>.jar可以运行;

如果没有图形界面,只能用命令行的方式运行;

如果你做了GUI,可以直接双击运行。



如果导出JAR File没有选择main函数会怎么样?



JAR File和Runnable JAR File的区别?

The runnable jar contains a MANIFEST.MF file, which defines the Main class to be executed when the jar is run. The “Main-Class” must be defined so the java runtime knows which class to call when the jar is “run.”

If a jar does not include a manifest with the “Main-Class:” it is not considered a “runnable jar” - it is just a library of Java code.

参考资料

https://stackoverflow.com/questions/4974693/java-eclipse-difference-between-exporting-as-a-jar-and-exporting-as-a-runnable
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: