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.