java 运行jar文件和exe的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27769662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between running jar file and exe?
提问by Vegeta
If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?
如果你有一个小程序,你可以运行 jar 文件,它会工作得很好。但是如果你把jar文件转成exe文件,你还是需要java来运行你的exe文件,那么它们之间有什么区别,为什么有些人把jar文件转成exe文件呢?
回答by Will Hartung
An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.
从表面上看,EXE 是一个可执行程序,它启动本地 java 以执行包类。
As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc
files with your word processor.
您可能知道,在您的计算机上,您可以将某些文件扩展名与本地程序相关联。例如,.doc
带有文字处理器的文件。
Similarly, .jar
files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.
类似地,.jar
文件可以与Java 相关联,以便Java 可以执行它们。如果 jar 文件中捆绑了所有必需的类,并且有指向启动类的正确清单,则该 jar 文件被认为是“独立的”。
So, by associating .jar
with Java, clicking on it in your environment will launch Java with the given jar file.
因此,通过.jar
与 Java关联,在您的环境中单击它会使用给定的 jar 文件启动 Java。
An EXE doesn't need that association. It find java on its own with it's own launcher.
EXE 不需要该关联。它使用自己的启动器自行查找 java。
The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.
下一步是您实际上可以将 JRE 捆绑到一个 EXE 中,因此您甚至不需要让用户安装 Java 作为先决条件。但那是一个不同的过程。
回答by Journeycorner
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.
Java 存档或 jar 是可在 Java 虚拟机上运行的已编译 Java 字节码和资源的存档。“.exe”是 Windows 扩展,用于直接执行代码,主要由安装程序或不需要安装的程序使用。我认为您的“人”正在谈论安装程序。
回答by Monir Zaman
People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.
人们通常使用 Java 可执行包装器有两个原因 - 1. 为没有 JVM 的环境简单部署,以及 2. 确保用于开发应用程序的确切 Java 运行时用于运行 JAR。然而,这种做法并没有那么普遍。
回答by boakye_wozniac
An Exe file is an executable file that can be executed in Microsoft OS environment. Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment. The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.
Exe 文件是可以在 Microsoft 操作系统环境中执行的可执行文件。Jar 文件是 Java Class 文件的容器,包括与项目相关的其他资源。Jar 文件只有在 Java 运行时环境下才能执行。JavaTM Archive (JAR) 文件格式使您能够将多个文件捆绑到一个存档文件中。
The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.
java文件编译出来的.class文件,不能直接启动。这就是为什么需要将它转换为exe才能在windows环境下运行的原因。通常的通过批处理文件启动java程序的方式并不方便。所以为了避免这个困难,我们需要将jar文件转换成exe文件。
Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.
也将其转换为exe。使程序能够通过简单的双击程序运行,而不必使用 IDE 或通过 JVM 编译它。
回答by boakye_wozniac
All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".
exe 要做的就是使用您的应用程序启动一个 jvm,类似于:“java -jar app.jar”。