0

After ignoring Java updates for quite some time, I now want to move on from the somewhat shady Java 10.0.2 Runtime I found somewhere to Java 13. As it turns out, Oracle stopped the "monolithic" JRE philosophy after Java 8 and I can't seem to find any definitive answers to my questions on how I'd go about deployment.

Here's what I think stays the same:

  • IDE (eclipse) workflow mostly stays the same
  • If I want to use the program myself, I can compile it to a .jar that will run on the JVM that comes with the JDK, just like with a Java 8 runtime

Now, here comes the tricky part I can't wrap my head around: Deployment on other machines

  1. Create a module-info.java that lists the dependencies of that program
  2. Compile a .jar as always using the eclipse dialogue
  3. Use jlink to create a runtime image for that program to ship alongside

...But what now?

How are these images making the program work? I read that they're some sort of small JRE for that program alone, which would remove the need for Java to be installed on the target system, but how would that be cross-platform?

Or are they some sort of "patch" to the JRE that is available to download from the official site? That would explain why that is still being updated, but it wouldn't remove the need for Java to be installed on the target machine.

TL;DR:

  • Is there anything wrong with my understanding so far?
  • How do jlink-ed runtime images work?
  • How are they cross-platform?
  • Does the target machine still need any sort of pre-installed Java-related software e.g. a runtime / the runtime provided in the link?

Thank you very much for reading through my wall of text and thank you in advance for the answer!

EDIT: Made the point of question four clearer.

mindoverflow
  • 364
  • 1
  • 12
  • 1
    Images created by `jlink` are platform-specific. This isn't much different than how the JDK itself is platform-specific. If you want to target more than one platform you'll have to build multiple images, one per platform. Luckily, you [can apparently do this all from a single platform](https://stackoverflow.com/a/47594270/6395627). Note this doesn't stop the _Java code_ from being cross-platform. There's also a tool called `jpackage` (_early-access_) which allows you to build native executables/installers. However, unlike `jlink`, the `jpackage` tool won't support cross-platform building. – Slaw Oct 22 '19 at 18:00
  • I see, seems logical to me. Also jpackage looks very interesting. Thanks! – mindoverflow Oct 22 '19 at 20:43
  • 1
    To add, `jlink` simply creates a JRE but only with the modules needed by the application (including, if configured, any observable service provider modules). If you look at the output the directory structure looks very much like the JDK directory structure, just stripped down (e.g. no JDK tool executables). This is fully self-contained and does not require anything special installed on the target machine (ignoring application requirements). If you add launchers (via `--launcher`) then some scripts will be generated which will use the embedded JRE to run the application. – Slaw Oct 22 '19 at 21:41
  • 1
    Keep in mind that `jlink` requires your project and all your project's dependencies to be _explicit_ modules (i.e. no automatic modules and no classpath). That said, `jpackage` can handle creating an application which uses the classpath. This can even be combined with `jlink` by creating a image of all the explicit modules and then configuring everything else to use the classpath (if I remember correctly). – Slaw Oct 22 '19 at 21:48
  • 1
    You also should read up on JMOD files, which may be provided by some libraries. – Slaw Oct 22 '19 at 21:49

1 Answers1

0

All my questions have been answered by Slaw in the comments to the original question, so I'll sum them up here in this answer.

  • My understanding so far is correct
  • jlink creates a mini-JRE with the modules the program needs, as specified in module-info.java
  • They're not, one would need to e.g. Linux-JDK to create a linux-specific version etc.
  • All files needed to run/interprete the program are contained in the runtime image

Also thanks for the extr info! I'll make sure to look into JMOD, and from what I read about jpackage, it's something to be very excited for.

mindoverflow
  • 364
  • 1
  • 12