What is the difference in eclipse between exporting as a JAR file and exporting as a Runnable JAR file? Aren't they both runnable? What are the pros/cons of each?
导出为JAR文件和导出为Runnable JAR文件之间的eclipse有什么区别?它们都不是可以运行的吗?每个人的利弊是什么?
3 个解决方案
#1
90
The runnable jar contains a MANIFEST.MF file, which defines the Main class to be executed when the jar is run.
runnable jar包含一个MANIFEST.MF文件,该文件定义了jar运行时要执行的Main类。
Non-runnable jars are just libraries of classes, that can be added to the classpath so that code is reused (it also contains the manifest file, but no main class there)
不可运行的jar只是类的库,可以添加到类路径中以便重用代码(它还包含清单文件,但没有主类)
#2
19
A runnable jar is a jar file that has an embedded Manifest file that includes the "Main-Class:" declaration. 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.
可运行的jar是一个jar文件,它有一个包含“Main-Class:”声明的嵌入式Manifest文件。必须定义“Main-Class”,以便java运行时知道jar“运行”时要调用的类。如果jar不包含带有“Main-Class:”的清单,则它不被视为“可运行的jar” - 它只是一个Java代码库。
I would guess this is the difference in how Eclipse exports the jar, but not 100% sure.
我猜这是Eclipse导出jar的方式不同,但不是100%肯定。
See this link for more info: http://www.skylit.com/javamethods/faqs/createjar.html
有关详细信息,请参阅此链接:http://www.skylit.com/javamethods/faqs/createjar.html
#3
12
With the standard JAR file, you have to specify the class with the main method on the command line when running the jar. With a runnable JAR, there is a manifest file that will hold that information so you can just type java -jar myRunnable.jar
, or simply double click it.
使用标准JAR文件,您必须在运行jar时在命令行上使用main方法指定类。使用可运行的JAR,有一个清单文件可以保存该信息,因此您只需键入java -jar myRunnable.jar,或者只需双击它即可。
#1
90
The runnable jar contains a MANIFEST.MF file, which defines the Main class to be executed when the jar is run.
runnable jar包含一个MANIFEST.MF文件,该文件定义了jar运行时要执行的Main类。
Non-runnable jars are just libraries of classes, that can be added to the classpath so that code is reused (it also contains the manifest file, but no main class there)
不可运行的jar只是类的库,可以添加到类路径中以便重用代码(它还包含清单文件,但没有主类)
#2
19
A runnable jar is a jar file that has an embedded Manifest file that includes the "Main-Class:" declaration. 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.
可运行的jar是一个jar文件,它有一个包含“Main-Class:”声明的嵌入式Manifest文件。必须定义“Main-Class”,以便java运行时知道jar“运行”时要调用的类。如果jar不包含带有“Main-Class:”的清单,则它不被视为“可运行的jar” - 它只是一个Java代码库。
I would guess this is the difference in how Eclipse exports the jar, but not 100% sure.
我猜这是Eclipse导出jar的方式不同,但不是100%肯定。
See this link for more info: http://www.skylit.com/javamethods/faqs/createjar.html
有关详细信息,请参阅此链接:http://www.skylit.com/javamethods/faqs/createjar.html
#3
12
With the standard JAR file, you have to specify the class with the main method on the command line when running the jar. With a runnable JAR, there is a manifest file that will hold that information so you can just type java -jar myRunnable.jar
, or simply double click it.
使用标准JAR文件,您必须在运行jar时在命令行上使用main方法指定类。使用可运行的JAR,有一个清单文件可以保存该信息,因此您只需键入java -jar myRunnable.jar,或者只需双击它即可。