7

The instructions to javapackager just above Example 2-1 in the Java SE Deployment Guide/Self-Contained Application Packaging state that a jar file is required in the -deploy command.

If I use a modular jar, I get this error message:

Exception: java.lang.Exception: Error: Modules are not allowed in srcfiles: [dist\tcdmod.jar].

If I use the equivalent non-modular jar, the resulting package includes the complete runtime. But I want to use the reduced runtime I made with jlink that is in the /dist folder.

Can the javapackager command deploy with a jlink-generated runtime? How?

The section titled "Customization of the JRE" makes no mention of the javapackager command.

The following section "Packaging for Modular Applications" has a following line:

Use the Java Packager tool to package modular applications as well as non-modular applications.

Is the Java Packager tool distinct from javapackager? There are no examples using javapackager in this section.

Here is the javapacker command that I used:

javapackager -deploy -native -outdir packages -outfile ToneCircleDrone -srcdir dist -srcfiles tcdplain.jar -appclass com.adonax.tanpura.TCDLaunch -name "ToneCircleDrone" -title "ToneCircleDrone test"

The instructions in the javapackager documentation make no mention of the scenario where a jlink runtime is used. There is a Bundler argument -Bruntime but it is only used to point to an installed runtime other than the system default, AFAIK.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
  • An answer from java-gaming.org shows that it IS possible to connect to a jlink runtime. http://www.java-gaming.org/index.php/topic,38682.0.html#msg369300 I will elevate this comment to "answer" if I actually follow through and test it out. I may take the advice to use the jlink directly with 3rd party installer, instead. – Phil Freihofner May 16 '18 at 17:47
  • I ended up following an alternate course for deploying a jlink'd application: (1) command line compile, (2) use command line jlink, (3) use Inno Setup 5 to package the distribution created with jlink. All the steps are written up in a walk-through that is posted at java-gaming.org. http://www.java-gaming.org/topics/deployment-and-packaging/38754/msg/370016/view.html#msg370016 – Phil Freihofner Aug 20 '18 at 02:54

1 Answers1

4

The javapackager provided with JDK 9 and up uses jlink to generate the jre image:

For self-contained applications, the Java Packager for JDK 9 packages applications with a JDK 9 runtime image generated by the jlink tool. To package a JDK 8 or JDK 7 JRE with your application, use the JDK 8 Java Packager.

https://docs.oracle.com/javase/9/tools/javapackager.htm#JSWOR719

You can even pass arguments to jlink using -BjlinkOptions=<options>

Additionally, -Bruntime is only valid for packages deployed using -deploy -native jnlp

For compiling a modular application, instead of -srcdir, use --module-path <dir>, and then specify the main module using -m <module name>.

EDIT: While there is no documentation on -BjlinkOptions, it is present in the javapackager source

jdk.packager/jdk.packager.internal.legacy.JLinkBundlerHelper

https://github.com/teamfx/openjfx-10-dev-rt/blob/bf971fe212e9bd14b164e4c1058bc307734e11b1/modules/jdk.packager/src/main/java/jdk/packager/internal/legacy/JLinkBundlerHelper.java#L96

Example Usage: -BjlinkOptions=compress=2 will make javapackager run jlink with the --compress=2 flag, generating the JRE image with Zip Level compression.

Aditionally, running javapackager with the flag -Bverbose=true will show you exactly which arguments are being passed to jlink with a line in the output something like this:

userArguments = {strip-debug=1 compress=2}

robot_rover
  • 130
  • 8
  • 1
    Answer could be improved with either an example illustrating the use of -BjlinkOptions or link to doc of its usage, and with some context for the -Bruntime comment. Latter has aspects of a non-sequitur as currently written. How does this command relate to the question being answered? The part explaining how to modify a command using -srcdir to using --module-path for modular application is very helpful (assuming it works). But it would be more helpful if complete line example were written using either my example or a javapackager doc scenario example as starting point for the needed changes. – Phil Freihofner May 31 '18 at 19:27
  • Thanks for providing additional information in your edits. I can upvote your answer, but I haven't taken the time to test if it works, as I am now using JLink via command line, and packaging with InnoSetup5. – Phil Freihofner Jun 14 '18 at 20:36
  • It seems to me like there has been plenty of opportunity for others to raise questions if there was any issues with this answer. Since there are no objections I'm selecting it as a valid solution. However, I'm doing so with a concern that I have not personally tested it, but have taken another path. – Phil Freihofner Nov 22 '18 at 18:45