Search code examples
javajavafxjpackage

Package a JavaFX Application as a Native Executable WITH resources


Based on this article, and with a default JavaFX tree from IntelliJ Idea (see below), how do I add all resources to commands so that they can be used natively (with getClass().getResource("/style/style.css") or some other way)?

src
|_ main
   |_ java
      |_ helloworld
         |_ HelloWordlFX
      |_ module-info.java
   |_ resources
      |_ fonts
         |_ openssans
            |_ opensansregular.ttf
      |_ pictures
         |_ icon.ico
      |_ style
         |_ styles.css
      |_ fxml
         |_ sample.fxml
...

Sincerely,

I'm wondering if I should transform the resource folder into a jar, and load it as a module, if there is a specific command to include it in my module, or if the solution lies in using JPackage. I tried --resource-dir src/main/resources with jpackage but to no avail.


Solution

  • Based on the article, @slaw's answer, respecting the tree structure chosen in my question, and for a Microsoft Installer (msi) file:

    1.Maven lifecycle > package

    2.jpackage to msi :

    jpackage 
     --dest output 
     --name ShiftingCircle 
     --type msi 
     --module-path "%PATH_TO_FX_JMODS%;target/<NAME>.jar" 
     --add-modules helloworldfx 
     --module helloworldfx/helloworld.HelloWorldFX 
     --win-shortcut --win-menu 
     --java-options -Xmx2048m