How to create an .exe program with Java?

Hi everyone, what is the easiest way to create an .exe program with Java?

Is there a variant that works without having Java on the PC?

Ps: I have a finished program of course, it's just a matter of getting it usable for a user

2 votes, average: 2.00 out of 1 (2 rating, 2 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
16 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jo135
1 year ago

The most reliable is GraalVM Native Image, where a compiler toolchain must be installed.

https://www.graalvm.org/22.0/reference-manual/native-image/

Otherwise, there is the possibility to bundle a JDK with the application, even with the installer.

https://www.baeldung.com/jlink

https://www.baeldung.com/java14-jpackage

CSANecromancer
1 year ago
Reply to  EVILKNIVL

and this can run it without extra installations

Then Java is the wrong choice with its architecture. The strength of Java is that it runs on all possible platforms. To do this, Commission but a corresponding runtime environment is installed on the respective platform.

Theoretically, your Java program would also be running on my Linux system. But with a .exe, my computer can't start. That's why I need the Linux runtime environment and could run your .jar in it.

It looks similar on Windows. There it is then the JRE: Java Runtime Environment or in German: Java runtime environment.

jo135
1 year ago

What is the next step to have a running program for a non-coder user?

The things I described in my answer. This allows you to build a nicely packaged program that you don't see as a "non-coder" that it is written in Java.

Nevertheless, one must say, of course, that this is not the most common application for Java. It is mainly used for large services that are not used directly by end users on their own devices (besides Android apps that are also commonly written in Java). These are the applications that run on the thick server landscapes in the background. As a layman, you get little of it, but that's where "the software" plays out today.

Xandros0506
1 year ago

what is the easiest way to create a .exe program with Java?

JAVA is not intended for this. Java programs SHOULD run in the JVM to be platform independent.

If the programs were not encapsulated in a JVM, it would be impossible to achieve the platform impractice. If you want your code to be compiled as an independent running program in an exe for Windows, then use a language that uses a compiler for Windows. (C++/C#/VB/Delphi as examples.)

joernius
1 year ago

Enabled program does not necessarily have to be in exe format.
Java also has a jar format. If the target computer has no Java installed, it should function as a portable app in which the Java runtime file is integrated.

Yes, it is possible to connect a Java program with a Java runtime file in a portable app, so it also works on a PC without installed Java.

Gemini confirms my acceptance:

Two approaches:

1. Pack Java program in a JAR file:

  • Compile Your Java program with
  •  javac
  • .
  • Create a JAR file with
  •  jar
  • . This file contains the compiled Java bytecode as well as all necessary resources (eg pictures, audio files).
  • Connect the Java Runtime Environment (JRE) into the JAR file. There are various ways to do this.
  • By JLink: The Java tool
  •  jlink
  • allows to create a minimalist JRE that only contains the required modules.
  • Launch4j: Launch4j is a cross-platform tool that allows you to convert Java programs to native executables (.exe, .app).

Two. Java program as portable app with JRE:

  • Create a portable directory which contains all required files:
  • Your Java program (JAR file)
  • The Java Runtime Environment (JRE)
  • A start script (eg batch file or shell script) that starts the Java runtime environment with the right Java program.

Advantages:

  • portability: The Java program can be run on any PC, regardless of whether Java is installed or not.
  • Compatibility: The Java program runs on all common operating systems (Windows, macOS, Linux).
  • simplicity: The use of a portable app is simple and convenient.

Cons:

  • Size: The portable app can be larger than the original JAR file as it contains the JRE.
  • Complexity: Creating a portable app can be a bit more complex, especially if you want to use JLink or Launch4j.

Further information:

HardwareFreak3
1 year ago

Ask the user to install Java.

guteantwort626
1 year ago

Is there a variant that then works without having java on the pc?

Then you'd have to pack a Java Runtime into your program, then that should go. Unfortunately, I don't know what it looks like with the Java license.

jo135
1 year ago
Reply to  guteantwort626

Unfortunately, I don't know what it looks like with the Java license.

Completely unproblematic. There are only individual commercial JDKs (approximately Azul) that do not allow this easily.

Since approx. Java 9 is also the method recommended by Oracle for desktop apps to deliver a JVM instead of relying on a system-wide installed.

Apart from that, you can also build native binaries with GraalVM.

guteantwort626
1 year ago
Reply to  jo135

Thanks for the info, again what learned 🙂 I can do something Java but have never really dealt with desktop programs.

jo135
1 year ago

Not really the strength of Java, but it is.