Reputation: 64
I created a javafx application via the IDE IntelliJ IDEA on ArchLinux. Now, I want to start this program without any IDE, so I created a .jar file. When trying to start the program with java -jar myprogram.jar, then I get the error message that runtime components for javafx are missing. Fine - I'll add these with the --module-path option, and it runs.
However, this --module-path thing only works somehow when I set the module path being somewhere in /lib/... On the other hand, when I try to copy the javafx modules into the folder where the myprogram.jar file is and set the module path there, the modules cannot be found.
My issue is the fact that I want to "self-contain" everything possible in one folder, such that I could copy&paste everything on another machine where the JVM is installed and just run it, and do not want to depend on the specific path where the javafx modules are installed. Maybe there is another way than to customize the --module-path?
Any help? Thanks :-)
Upvotes: 2
Views: 3393
Reputation: 159536
Forget about trying to create a single executable jar that includes JavaFX components and depends on a pre-installed JVM (it is not a supported configuration).
However, cwellm's answer here details a method that keeps the modular JavaFX dependencies separate from the created application jar by keeping the JavaFX modules in separate jars added to the module path, I believe that this might be a valid and supported deployment configuration. It does require deploying multiple jar files to the client in the right locations in order for it to work. Another alternative would be to assume a distribution of the JDK such as liberica or corretto which can come with JavaFX included in the base JDK distribution, then you don't need to specify a module path for JavaFX as it will already be present in the default boot module path for the JDK.
Recommended Solutions
Instead create a runtime image using jlink, this can be done by (among other methods) using the openjfx maven plugin.
Or if you want an installer, use jpackage which can also (among other methods) be created using maven, see JPackageScriptFX as an example.
jpackage doesn’t create archlinux native packages. So if you want that, then jpackage wouldn’t be the thing to use. Instead you could use a maven assembly or tar call to create a zip or tar.gz of the jlink output, or use the pacman tool to create a native archlinux package of the same.
Or if you like gradle see the badass jlink and runtime plugins.
Using a build tool (maven or gradle) to include the JavaFX dependencies rather than relying a JavaFX sdk download is preferred IMO. Also, if possible, define a module-info. Then jlink can be used to create the required runtime from your app, it’s dependencies and the jre, as well as the execution script for the app, so that things are self-contained. Native packages in rpm or deb format created by jpackage takes this further. Installing apps packaged this way also ensures all required OS lib dependencies are correct.
If you want to understand more see the contextual info (FAQ section) in this answer:
Upvotes: 2
Reputation: 64
It is possible to put several custom module paths into the command --module-path. It is important to really put in the full path of the required modules, including the filename of the module itself. For instance, let's assume I want to include the modules module1.jar and module2.jar for the execution of MyApplication.jar, and all of these files are put into the same folder, say /my/custom/folder. Then the command line command would look like this:
java -jar --module-path /my/custom/folder/module1.jar:/my/custom/folder/module2.jar --add-modules module1,module2 MyApplication.jar
Upvotes: 1