1

I want my program to be usable by systems which do not have a JRE preinstalled.

What I'm a little bit struggling with right now is how can I tell Maven to use an embedded JRE and not the system JRE? Right now to build my application I'm using the maven-assembly-plugin along with the maven-nativedependencies-plugin to resolve native dependencies and the maven-jar-plugin.

My understanding in theory is somewhat of the following:

  1. Copy(?) JRE into my project folder (e.g. a folder with java8)
  2. Zip everything up (Somehow included in my build process)
  3. Tell Maven to use the included JRE
  4. User can unpack and does not need a preinstalled JRE

I assume that I somehow need to tell maven/my application to unpack that shipped JRE and use it? I already read about the Java 9 Deployment guide (I'm using Java8 though) and jlink'ed images, however all of it seems a little bit tricky and I'm not build process expert.

Could anyone share their experiences / thoughts on that topic?

LOLWTFasdasd asdad
  • 1,071
  • 2
  • 18
  • 30

1 Answers1

1

There are few ways to build an executable image:

  1. If you are on Java 9 you can use jlink to build an executable runtime image.
  2. Use launch4j tool to include JRE e.g. as shown in this answer.
  3. Include JRE as a Maven dependency and repackage with assembly plugin. Do note that this dependency is quite outdated.

    <dependency>
      <groupId>com.oracle.java</groupId>
      <artifactId>jre</artifactId>
      <version>1.8.0_131</version>
    </dependency>
    
Karol Dowbecki
  • 38,744
  • 9
  • 58
  • 89
  • Including the JRE as Maven dependency sounds promising to me. Could you maybe elaborate a little bit on what you mean with "repackage with assembly plugin" (simply run a build process)? If the user has unpacked the folder and is executing the JAR how does it know that it has to use the JRE shipped in the folder? – LOLWTFasdasd asdad Apr 22 '18 at 14:08
  • It's an outdated JRE from 2017-04-18 and there is no promise that Oracle will ever release a new version. I really woudln't invest into this approach. You can use `maven-dependency-plugin:unpack` to extract whatever files are part of this dependency and then `maven-assembly-plugin` to build a runtime archive. – Karol Dowbecki Apr 22 '18 at 14:12
  • So you would rather recommened to go with launch4j? – LOLWTFasdasd asdad Apr 22 '18 at 14:26
  • 1
    Personally I'd assume that tools shipped with the JDK e.g. `jlink` and `jdeps` is the best approach if you can use JDK9 or JDK10. – Karol Dowbecki Apr 22 '18 at 14:27
  • I also read about jsmooth, seems to be similiar to launch4j, maybe you could add it to your answer for completeness: http://jsmooth.sourceforge.net/ – LOLWTFasdasd asdad Apr 23 '18 at 10:15