On 21/10/2024 19:19, Alex Buckley wrote:
On 10/21/2024 9:14 AM, Mark Reinhold wrote:
https://openjdk.org/jeps/493

I was surprised to learn that the jlink tool which can link from a run-time image is only available in a JDK built with --enable-linkable-runtime. As a user, can I tell if the jlink tool in my installed JDK consumes JMODs or consumes run-time images?

I am also not crystal clear whether jlink in a JDK built with --enable-linkable-runtime is capable of consuming run-time images _and_ JMODs, or just run-time images.

If it can consume run-time images _and_ JMODs, which origin is preferred when resolving modules passed to --add-modules?

Can it consume only the run-time image it was built as a part of, or can I point --module-path to other run-time images? (presumably built with --enable-linkable-runtime themselves)

It would be good if the JEP could clarify these points for all readers.

As an editorial note, this text can't be true: "The jlink tool in the resulting JDK works exactly the same way as the jlink tool in a JDK built with the default configuration." -- the jlink tool in the resulting JDK will extract from the run-time image, not from JMOD files, so it's not working "exactly the same way". I think you mean that _running_ the jlink tool in the resulting JDK is done in exactly the same way.

As a user, the JDK you download may contain a "jmods" directory, it may not. This should just work:

    $JDK/bin/jlink --add-modules java.se --output myjdk

It doesn't matter if jlink uses packaged modules in $JDK/jmods or reconstitutes the module content from $JDK run-time image by other means. That was the intention of the example and "The jlink tool in the resulting JDK works exactly .." in the Description.


Every jlink in every JDK build can consume JMOD files. I'm trying to see if there is anything in the JEP that suggests otherwise. I don't expect most developers will come across JMOD files, except developers using JavaFX where a command line this will just work:

   jlink --module-path javafx-mods --add-modules javafx.graphics,javafx.web,java.se --output myjdk

The JavaFX modules (in JMOD format) will be found in javafx-mods. The java.* modules will comes from the JDK.


jlink support for using the packaged modules in another JDK is very limited. You can do this today:

  $JDK1/bin/jlink --module-path $JDK2/jmods --add-modules java.se --output myjdk

but only if $JDK1 and $JDK2 are the same version, otherwise you get an error like "Error: jlink version 24.0 does not match target java.base version 22.0".

The motive for this is cross-linking where you run jlink on one platform to produce the run-time images that you need for all platforms.

The JEP doesn't change anything in this area. This cross linking needs packaged modules so can't point to the jmods directory of a JDK built with --enable-linkable-runtime as there is no jmods directory. This is the "Cross-linking" item in the Restrictions section but it might be that this term is not widely known so the implications of item 3 may not be clear.

-Alan







Reply via email to