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.
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?
解决方案
It is not recommended because:
The standard Java tool chains do not support it.
An exe is not portable. Different exe 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.
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.
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 - 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.