为什么不建议从Java程序创建.exe? [英] Why is creating an .exe from a java program not recommended?
问题描述
我正在学习有关使用Java进行GUI编程的知识,并且正在使用Netbeans IDE.我现在想创建一个在Netbeans外部运行的可执行程序.即可以在我的桌面上运行.
I am learning learn about GUI programming with Java, and I am using the Netbeans IDE. I would now like to create an executable program to run outside of Netbeans; i.e. so that it can be run from my desktop.
但是当我做一些研究时,我得到的印象是不建议从Java程序创建.exe.您能不能向我解释为什么不建议这样做?
But when I did some research, I got the impression that creating an .exe from Java program is not recommended. Would you please explain to me why it is not recommended?
推荐答案
不建议这样做,因为:
- 标准Java工具链不支持它.
-
exe
不可移植.不同的exe
格式用于不同的操作系统,硬件体系结构等. - 用于Java程序的独立的
exe
需要包含完整的JRE. (您是否要分发100Mb的"hello world"可执行文件?) - 带有嵌入式JRE的Java
exe
是出于安全考虑.没有简单的方法来更新JRE ...以修复最新一批的安全漏洞.
- The standard Java tool chains do not support it.
- An
exe
is not portable. Differentexe
formats are used for different operating systems, hardware architectures, etcetera. - A self-contained
exe
for a Java program needs to contain a full JRE. (Do you want to distribute 100Mb "hello world" executables?) - A Java
exe
with an embedded JRE is a security concern. There is no easy way to update the JRE ... to fix the latest batch of security holes.
如果(假设地)Java语言,库和工具链支持编译为二进制+链接,那么分发exe
文件将是一个明智的解决方案.但是,Java应用程序可以完成的很多事情都取决于标准Java的动态加载/JIT编译实现.
If (hypothetically) the Java language, libraries and tool chain supported compilation to binary + linking, then distributing exe
files would be a sensible solution. However, a lot of things that a Java application can do depend on standard Java's dynamic loading / JIT compilation implementation.
曾经有/第三方试图满足人们对独立的exe
文件的要求,但是您要么得到一个Java子集 1 ,要么就变成了膨胀的exe
文件.
There have been / are third-party attempts to meet people's requirements for self-contained exe
files, but your either end up with a Java subset1, or bloated exe
files.
1-例如,对于旧的GNU gcj
编译器,该库是Java 2(!)...的子集,并且(AFAIK)不能动态加载字节码.有关gcj限制的详细信息,请参见此页面
1 - For example, with the old GNU gcj
compiler, the library was a subset of Java 2 (!) ... and (AFAIK) dynamic loading of bytecodes was not an option. For more information on gcj limitations, see this page.
这篇关于为什么不建议从Java程序创建.exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!