Select your language > /

Java: How to generate Windows, Linux and MacOS executables?

In favor of a "command line" type program, with Maven

Le 12/12/2022

If, like me, you are tired of making command line programs in Java and having to run them with this kind of things:

$ java -jar demo-app-v1.0.0-SNAPSHOT.jar arg1 arg2 arg3`

This little article should please you. You will then be able to do this directly:

$ ./demo-app arg1 arg2 arg3

Appetizing!

In this little tutorial, I will generate an executable file :

  • for Linux and MacOSX,
  • for Windows, an .EXE,
  • as a classic Runnable JAR.

However, this requires the presence of a JAVA Runtime (JRE and/or JDK) on the machine that will run it, although there are also solutions to embed a JRE.

The solutions I will describe do not use GRAALVM and its native compilation.

Functional Switch/Case with Java 8+

because the new Switch/Case statement with Java 12 gave me a weird idea

Le 26/02/2020

Java 12 was released on 20/03/19, bringing a new way to write switch/case control structures. This gave me an idea, admittedly a bit strange, to revisit the traditional switch/case from a functional programming point of view by using lambdas and a small Switch class, all in JAVA 8!

Be careful though, it is certain that this approach is much less efficient than a classic switch/case, but I don’t give up the beauty of the gesture.

Versions of this article:

  • 04/10/2019: first publication.
  • 26/02/2020 : following a judicious idea posted on “developpez.com” forums, see the “Let’s go further …” part.

Language warning.

The posts on this site are primarily written in French then human translated into English. Some articles are available in English but most of them are only available in French up to now (2023).

Guru Meditation #00000004.0000AAC0