1

In addition to developing classic services on Spring Boot, I want to know Java with it environment better. When I began to study portability, I came across such concepts as custom JRE (jlink, jmods) and native image (GraalVM, Liberica NIC).

As I understand :

  • Custom JRE for creating distribution folder with executable file. In folder only necessary dependencies. It arrived in Java 9
  • Native image for creating executable all in one JAR

Which of them should be used in which cases?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
MRoose
  • 11
  • 3

1 Answers1

3

First of all, you should know what a JRE (Java runtime environment) is. Basically, it includes everything required to run Java applications that are already built. A JDK (Java Development Kit) is a superset of a JRE, adding the tools for developing Java applications.

With jlink, you can create JRE images. This means you are creating a Java installation that is capable of running your Java program. This can be done in a way so it only contains the necessary modules. jpackage allows you to create an installer for such a JRE.

On the other hand, a native image is a version of your code that's compiled and optimized for a specific target platform. Typically, it's a single executable file that runs your code. When creating a native image, it takes your application and converts (compiles) it to a platform specific executable (unlike jlink which creates a JRE that is able run your "normal" JAR).

Native-image does not generate a JAR but an ELF/EXE file which can be executed on your device without a Java installation while jlink just creates a (minimal) Java installation capable of running your application.

It should be noted that native-image comes with a few limitations. For example, remote class loading is not possible and if you use Reflection, you need to specify what to reflectively access at compile-time.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
dan1st
  • 12,568
  • 8
  • 34
  • 67