When should you prefer jlink and when should you avoid it?

jlink is a Java tool that allows you to create custom runtime images, which contain only the modules necessary for your application. It can be a powerful way to optimize the deployment of Java applications, but it is not always the best choice. Here's a breakdown of when to use jlink and when to avoid it:

When to Prefer jlink

  • Modularity: If your application is modularized (using the Java Platform Module System), jlink can create a smaller runtime that includes only the required modules.
  • Performance: A custom runtime can lead to faster startup times and lower memory usage since only necessary modules are included.
  • Distribution: Ideal for packaging your application for production, as it simplifies the distribution by providing a self-contained runtime.

When to Avoid jlink

  • Simplicity: If your application is simple and doesn’t require modularization, the overhead of using jlink may not be justified.
  • Legacy Systems: It may not be suitable for legacy applications that rely on the traditional classpath, as jlink works best with modular applications.
  • Development Convenience: During development, sticking to familiar Java conventions and using traditional JDK may be easier.

jlink Java modularity Java Platform Module System runtime images packaging performance distribution