0

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?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 3
    _"But when i do some research, i got a conclusion that creating .exe from java program is not recommended"_ where did you find that exactly? Im sure they already explain the _"why"_ part there – Baby Jan 17 '17 at 07:37
  • `create an executable program without netbeans like something we put on our desktop. ` what do you mean by this? do you think that netbeans works as some kind of framework and wont let you use your java program without it? If you want to create a desktop application, then you only need to compile your programm and afterwards execute the .jar file. the only advantage of a .exe file is, a unique process name and a display icon – Angry Red Panda Jan 17 '17 at 07:37
  • 3
    See [What's the best way to distribute Java applications?](http://stackoverflow.com/questions/80105/whats-the-best-way-to-distribute-java-applications) – Yousaf Jan 17 '17 at 07:38
  • I am guessing you want to create an executable. Have a look at this post: http://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file – John Jan 17 '17 at 07:43

1 Answers1

5

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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 1
    In addition to what Stephen C remarked, Java has a deployment toolkit comprising JAR distribution, JAR derivatives WAR and EAR, and Java Web Start. These provide portable mechanisms to deploy and run Java programs without the need for EXEs. – Lew Bloch Jan 17 '17 at 08:08
  • @LewBloch - And there are other approaches too. – Stephen C Jan 20 '17 at 23:26