0

I use jpackage (with JDK 14) for creating a standalone JavaFX application.

The output of jpackage looks strange, it consists of two the same copies of JRE and all files in app folder, except App.cfg file, can be deleted without any problem.

Does jpackage can do not generate unnecessary files?


What I have:

I have a simple project created from Maven archetype org.openjfx:javafx-archetype-simple:0.0.3. And I just added maven-shade-plugin for creating jar with dependencies and a simple launching class for it (like NewMain class here).

I do:

mvn package
mvn javafx:jlink
jpackage --package-type app-image --dest targetApp --name App --runtime-image target/image --main-jar testApp-1.0-SNAPSHOT.jar --input target

As result I have two folders with JRE (absolutely the same ones):

  • targetApp\App\runtime
  • targetApp\App\app\image

And all files (and folders) (JRE (~53 MB), Jar (~9 MB), classes...) in targetApp\App\app can be safely deleted, except App.cfg file.

After deleting these files I run targetApp\App\App.exe and it works fine.

The deleting reduces the size of App from 118 to 56 MB.


An additional question: I use Windows and jpackage generates the result for Windows (a lot of dll files and exe), do I can create a standalone application in Windows for Mac and Linux?

KeyKi
  • 2,693
  • 3
  • 12
  • 24

3 Answers3

1

You get this result because you already created an uber-jar which contains everything in addition to what you specified via --input target which, according to the documentation, has the following effect.

All files in the input directory will be packaged into the
application image.

Try whether it works to just remove the option --input target or don't create the uber-jar. Instead use the maven-dependency-plugin to copy all dependencies into a single folder, say target/libs, and then explicitly specify --input target/libs.

Your second question: You cannot cross-create applications for other targets, if that is your question.

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Yeah, it's the reason. But `--input` is a required option. Well, I have specified `outputDirectory` for `maven-shade-plugin` and `maven-jar-plugin` so I have the directory that contains only jar file for `--input`, but anyway I have to manually to delete this jar from `targetApp\App\app` later. – KeyKi Nov 09 '19 at 10:53
  • Should say, that it's strange, that I can delete the jar from `targetApp\App\app` and the program still works. I don't see any file that may contains the program logic, but it works. I have even checked the work in clear Windows in VM. – KeyKi Nov 09 '19 at 10:57
  • Upd: they are probably in `targetApp\App\runtime\lib\modules` file. – KeyKi Nov 09 '19 at 11:07
  • I have tested it a bit more. So, it's not important that type of JAR you use, you get the same result for JAR, uber-JAR, JAR-with-dependencies (JAR and JARs in libs folder). The difference is only one – unnecessary JAR or JARs in `targetApp\App\app` folder that you should manually delete. – KeyKi Nov 10 '19 at 07:04
0

You might want to check out the JPackageScriptFX project on GitHub. It contains a sample multi-module maven project structure and build scripts for Mac and Windows that will build all available package types and executables for both platforms. You can find it here: https://github.com/dlemmermann/JPackageScriptFX

0

My solution without Oracle's jpackage:

AdoptOpenJDK + jpackager + macOS => .pkg, .dmg

  • Download AdoptOpenJDK_13. Unzip and put into /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk
  • Download jpackager for (in my case osx) from https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022500.html. Unzip.
  • Copy jdk.packager.jar and jpackager to the /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/bin (!!!)
  • In /yourworkspace/target should be the programA.jar file. (In my case it is a small program created with OpenJFX + openjdk13)
  • The /yourworkspace/jlink denotes on your JRE with bin,lib etc. you might have created via jlink. (In my case I have my custom JRE + JavaFX modules)
  • The /yourworkspace/icons contains .icns .
  • create jpackager.command file in your workspace with the content:
#! /bin/bash
ABSPATH=$(cd "$(dirname "$0")"; pwd -P)
launcher=`ls $ABSPATH/target/*.jar`
for eachfile in $launcher
do
    if [ -f "$eachfile" ];then
        echo Creating .pkg ...
        echo "$eachfile"
        basename="${eachfile##*/}"
        /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/bin/jpackager \
        create-installer \
        --runtime-image $ABSPATH/jlink \
        --name ProgramA \
        --input $ABSPATH/target \
        --main-jar $basename \
        --version 1.0 \
        --copyright "Nikita Gromov 2020" \
        --name "ProgramA-macos" \
        --mac-bundle-name "ProgramA" \
        --output $ABSPATH/appimage \
        --icon $ABSPATH/icons/20200220101822955_easyicon_net_32.icns
     fi
done

Double click on jpackager.command which is located in /yourworkspace and wait until the jpackager has created ProgramA-macos-1.0.pkg and ProgramA-macos-1.0.dmg under /yourworkspace/appimage

My solution without Oracle's jpackage:

AdoptOpenJDK + jpackager + Windows => .msi

  • Install WiX (!!!) Important step.
  • Download AdoptOpenJDK_11. Will be installed under C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot
  • Download jpackager (in this case win) from https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022500.html. Unzip.
  • Copy jdk.packager.jar and jpackager to the C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin (!!!)
  • In /yourworkspace/target should be the programA.jar file. (In my case it is a small program created with OpenJFX + openjdk11)
  • The /yourworkspace/jlink denotes on your JRE with bin,lib etc. you might have created via jlink. (In my case I have my custom JRE + JavaFX modules)
  • The /yourworkspace/icons contains .icns .
  • create jpackager.bat file in your /yourworkspace folder with the content:
set openjdk=C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin
set saveto=%cd%
cd %openjdk%
jpackager create-installer --runtime-image %saveto%/jlink --input %saveto%/target --main-jar ProgramA.jar --version 1.0 --copyright "Nikita Gromov" --name "ProgramA-win" --output %saveto%/appimage --icon %saveto%/icons/icon.ico --win-menu --win-shortcut --win-dir-chooser

Note The ProgramA.jar should be in /yourworkspace/target path (!!!)

Double click on jpackager.bat which is located in /yourworkspace and wait until the jpackager has created ProgramA-win-1.0.msi under /yourworkspace/appimage

Custom JRE + JavaFX mods on Windows

Create /yourworkspace/jlink.bat file. The content of it should be:

SET openjdk=C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin
SET fx=C:\Programme\AdoptOpenJDK\javafx-jmods-11.0.2
set saveto=%cd%
cd %openjdk%
jlink --module-path %fx% --add-modules=javafx.base --add-modules=javafx.controls --add-modules=javafx.fxml --add-modules=javafx.graphics --add-modules=javafx.web --add-modules=javafx.media --add-modules=javafx.swing --bind-services --output "%saveto%\jlink"

This creates the /yourworkspace/jlink folder with a custom JRE+JavaFX libraries which you will link to jpackager.

Imeksbank
  • 104
  • 5