Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module javafx.controls not found in Java 9

I have two JPMS module in two files: modulea.jar and moduleb.jar. Modulea requires javafx.controls module. I need to use these modules in new layer, so I do:

ModuleFinder finder = ModuleFinder.of(modAPath, modBPath);
ModuleLayer parent = ModuleLayer.boot();
Configuration cf = parent.configuration().resolveAndBind(finder, ModuleFinder.of(), new HashSet<>());
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer newLayer = parent.defineModulesWithOneLoader(cf, scl);

I thought that JDK modules will be loaded automatically but I get

Exception in thread "main" java.lang.module.FindException: Module javafx.controls not found, required by modulea
    at java.base/java.lang.module.Resolver.findFail(Resolver.java:889)
    at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
    at java.base/java.lang.module.Resolver.bind(Resolver.java:297)
    at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:428)
    at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:230)

At the same time when I do: java --list-modules, the output is:

...
javafx.base@9
javafx.controls@9
javafx.deploy@9
javafx.fxml@9
javafx.graphics@9
javafx.media@9
javafx.swing@9
javafx.web@9

How to fix it?

like image 780
Pavel_K Avatar asked Sep 21 '17 17:09

Pavel_K


People also ask

How do I fix JavaFX error?

If this is your case also, you can do fix this by simply right-clicking on the javaFX project folder-> Build Path-> Configure Build Path-> Select JavaFX SDK-> Remove library-> Select classpath -> add library-> user library-> select library-> apply. Save this answer.

Does JavaFX run on JDK 11?

For JDK 11 and later releases, Oracle has open sourced JavaFX. You can find more information at OpenJFX project.

Does Java 10 have JavaFX?

It is bundled in the current JDK 9 and will remain in JDK 10, due this spring. Commercial support for JavaFX in JDK 8 will continue through at least 2022. Featuring a set of packages for graphics and media, JavaFX has been part of the JDK download since 2012.


1 Answers

From @AlanBateman's comment:

The javafx.controls module is not loaded by default. You can force it into the boot layer by running with --add-modules javafx.controls.

NOTE: Starting with Java 11 JavaFX is a separate project.

like image 80
Pavel_K Avatar answered Nov 13 '22 17:11

Pavel_K