Multi-module JavaFX maven project packaging issue

Packaging via mvn package using the maven-jar-plugin is not enough

mvn package, by default, is just going to package the jar for your application code, it isn’t going to include all of the dependant library code (which is why the dependent code cannot be found when you attempt to run your application).

You could package your application code and dependant libraries using an assembly, as detailed in How can I create an executable JAR with dependencies using Maven?, though that approach is not the only one to solve your problem.

You need to build some kind of runtime image

There are numerous options for building runtime images and I don’t know your requirements, so I can’t recommend what you should do instead. Example options are:

  1. A zip/tar of your application plus libraries in a separate directory.
  2. The creation of a single jar that includes all dependant code.
  3. Either of solutions 1 or 2, plus the inclusion of a packaged JRE.
  4. A runtime image with your code and libraries which also uses just the custom runtime portions of the JRE and JavaFX modules you need (using jlink).
  5. A native installer for either 3 or 4 (using jpackage + a native installer creation tool, e.g. WIX, RPM, DEB installer creators).

The last method (native installer), is the packaging, distribution, and installation method I would recommend for most non-trivial applications.

You need to research how to do this

To get your solution, you will need to do your own research, and, once you have chosen an approach and toolset, you could create a new question regarding the implementation of that approach, if you continue to have difficulties.

Related resources

Warning for shaded jars

If you bundle all JavaFX code into a single jar using the maven shade plugin, you will get a warning like the following when you run your application from Java 16+:

WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @28c71909'

This indicates that such a configuration is not supported, and may (and probably will) break in future and perhaps current JavaFX platform revisions. Thus, shaded jars that include JavaFX platform code are not recommended by me, even though such jars might currently work for your deployments.

JavaFX 11+ is built to be used as a set of modules. Configurations are not supported if they do not run the JavaFX platform off of the module path but instead run the platform code off of the classpath (as a shaded jar would).

Leave a Comment