working example of a javafx app discovering at run time 2 JPMS modules which have conflicting dependencies and loading them to separate layers
In your favorite IDE, open the parent project and run "clean and build". Or outside of your IDE, open the command line in the parent's project root folder and run mvn clean install
Launch the run.bat file, which contains:
java --module-path mods/gui --module net.clementlevallois.javafxtest.gui
- the
GUI
directory contains the JavaFX app, and the code loading the modules at runtime - the
logic
directory contains the interface for modules. These interfaces are often calledapi
orserviceobserver
in other demo projects for jpms modules. plugina
andpluginb
are toy modules which have conflicting dependencies: one of them depends on guava 10, the other on guava 23. In a non modular app, java would complain. Here the two modules can run together.
- the build places the built plugins and their dependencies in separate
mods/plugins/pluginxxx
folders gui
andlogic
are also placed in separate subfolders within themods
folders- the plugins are discovered in their subfolders by the main
gui
module thanks to a couple of lines at the beginning of the App.java main file.
The code for creating new layers for each plugin is adapted from Nikolai Parlog's demo for layers, which comes with his book on the Java Module System)
This should run without pre installed dependency on JavaFX, on any system (Mac, PC, Linux). But I am not 100% sure.
Feedback is welcome. Open an issue or get in touch on Twitter (@seinecle). I am not a professional Java dev, so I'll do my best to answer and direct you to complementary resources.