I have the following problem:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
When I try to run the default class of JavaFX project which send a "Hello World" button, I'm using Netbeans 11.1 as my IDE, the JDK 13, Jre-8u221. I create the library Java Fx and added it to the module path inn the properties of my project and on VM on run options included the command --add-modules javafx.controls, javafx.graphics.
You need to add the module-info.java file in the same package as the class that contains the Main method. Inside this file (and implicitly inside the module definition block), there should be at least 1 line:
requires javafx.controls;
This should fix your problem.
Related
MY SETUP:
I followed the steps for the JavaFX and IntelliJ -> Modular from IDE path.
I added the ikonli-core-12.2.0.jar, ikonli-javafx-12.2.0.jar and ikonli-carbonicons-pack-12.2.0.jar via the repository to the Scene Builder in this order. Here, they work fine.
Then I added those same .jars in that same order to the IntelliJ as described here: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project.
My module-info.java file contains the following code:
module project {
requires javafx.controls;
requires javafx.fxml;
requires org.kordamp.ikonli.core;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.carbonicons;
opens com.project to javafx.fxml;
exports com.project;
}
Picture of my libraries:
PROBLEM:
When I add an icon to the .fxml file and I click on Run, I get the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.kordamp.ikonli.javafx not found, required by project
The module name varies. Sometimes it says it's the javafx, others the core or the carbonicons.
I'm not sure why this happens. When I'm typing in the module-info.java file I get the autofill prompts, , but when I try, for example, import org.kordamp.ikonli.core; in my Main.java, it doesn't detect them.
I'm not sure why this happens. When I'm typing in the module-info.java file or try import org.kordamp.ikonli.javafx.FontIcon; in my Main.java, I get the autofill prompts, so it means it's detecting them.
If I remove the "ikonli requires" from the module-info.java and run it, I get this error (which is kind of understandable):
java.lang.ClassNotFoundException: org.kordamp.ikonli.javafx.FontIcon
SOLUTIONS I'VE TRIED:
Adding the .jars via File -> Project Settings -> Libraries.
This seems to automatically add them to the Modules -> Dependencies, but even so, the problem persists.
Adding them in the VM Options (Run -> Edit Configuration -> Modify Options -> VM Options) in various ways, right after the --module-path ${PATH_TO_FX}:out/production mentioned in the steps linked above (out can be safely changed to mods but I chose not to do that).
First:
--module-path ${PATH_TO_IKONLI_CORE}, --module-path ${PATH_TO_IKONLI_JAVAFX} and --module-path ${PATH_TO_IKONLI_CARBONICONS}
Doing this makes it so my actual project module doesn't get detected. I.E. I get this error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module project not found
Second:
--add-modules ${PATH_TO_IKONLI_CORE},${PATH_TO_IKONLI_JAVAFX},${PATH_TO_IKONLI_CARBONICONS}
This one produces a smiliar error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module /directory/path/to/file/ikonli-core-12.2.0.jar not found
Third:
--add-modules org.kordamp.ikonli.core,org.kordamp.ikonli.javafx,org.kordamp.ikonli.carbonicons
A similar error shows up:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.kordamp.ikonli.core not found
I tried File -> Reload all from disk and Invalidate Caches / Restart options, but they seem to have had no effect.
I created a lib folder in my src project folder, put the .jars there and added them as dependencies. Now they didn't show up in the External Libraries section (because they're not external obviously) but the problem remains (I'll re-add them as external again).
ADDITIONAL INFORMATION:
I've added controlsfx.jar the same way as the Ikonli .jars. The same error occurs for it as well.
They all have their module-info.class file in the proper directory as stated in the official javadoc, yet the ModuleFinder still throws the exception.
I've also checked my project.iml file and they all have the module-libraries with the correct directories present.
I've revisted the official Ikonli installation steps multiple times and everything checks out.
Though, in there it mentions that I need to have requires javafx.base; requires javafx.graphics; in the module descriptor. Not true, at least in my case, because when I add --show-module-resolution to the VM Options, it shows that they're loaded fine, but even when I do add them, the error still appears.
END
Sorry for the long post, I'm out of ideas and I don't know what else to try.
One of the comments here mentioned that they'd put their .jar in the mods/production folder. I did the same... and it worked. (╯°□°)╯︵ ┻━┻
I guess "Modular from IDE" doesn't agree with the IDE.
Looks like the proper way to go about modular is to use Maven/Gradle. I'll rebuild and go with Gradle.
I want to use opencsv in a project that is build with Java 14, using Java module system. So it has a module-info.java file.
A call to a method in opencsv works fine when it's initiated from a unit test, but throws an exception when initiated from the Main.main() method.
If I remove the module-info.java file, the method works fine in both cases.
The module-info file is simple, but probably wrong:
module opencsvDemo {
requires opencsv;
opens demo;
}
When running from Main.main(), I get
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Date
at commons.beanutils#1.9.4/org.apache.commons.beanutils.ConvertUtilsBean.registerOther(ConvertUtilsBean.java:730)
at commons.beanutils#1.9.4/org.apache.commons.beanutils.ConvertUtilsBean.deregister(ConvertUtilsBean.java:602)
at commons.beanutils#1.9.4/org.apache.commons.beanutils.ConvertUtilsBean.<init>(ConvertUtilsBean.java:161)
at opencsv#5.2/com.opencsv.bean.ConverterPrimitiveTypes.<init>(ConverterPrimitiveTypes.java:88)
at opencsv#5.2/com.opencsv.bean.AbstractMappingStrategy.determineConverter(AbstractMappingStrategy.java:739)
at opencsv#5.2/com.opencsv.bean.HeaderColumnNameMappingStrategy.loadAnnotatedFieldMap(HeaderColumnNameMappingStrategy.java:155)
at opencsv#5.2/com.opencsv.bean.AbstractMappingStrategy.loadFieldMap(AbstractMappingStrategy.java:405)
at opencsv#5.2/com.opencsv.bean.AbstractMappingStrategy.setType(AbstractMappingStrategy.java:343)
at opencsv#5.2/com.opencsv.bean.util.OpencsvUtils.determineMappingStrategy(OpencsvUtils.java:77)
at opencsv#5.2/com.opencsv.bean.CsvToBeanBuilder.build(CsvToBeanBuilder.java:210)
at opencsvDemo/demo.CsvGetter.get(CsvGetter.java:23)
at opencsvDemo/demo.Main.main(Main.java:13)
Is the error in my module-info.java file, or should I look somewhere else?
You can try using
requires java.sql;
in your module descriptor to ensure the module with the expected class is resolved correctly.
If the code compiled without that descriptor, there must be another module responsible for that. You would have to identify it and decide, further on the path to be chosen. It could have been due to dependencies of your project bringing in automatic modules with the same package, which could further cause a split package issue as well. In which case, looking for library updates, etc in favor of Java upgrade might help.
I've been trying to write Hello JavaFX app and faced with necessity consider about Java modules for starting the app.
F.e. javafx-maven-plugin's run goal produce such startup command:
[DEBUG] Executing command line: [C:\java\zulu14.29.23-ca-jdk14.0.2-win_x64\bin\java.exe,
--module-path, C:\.m2\repository\org\openjfx\javafx-base\14\javafx-base-14-win.jar;
C:\.m2\repository\org\openjfx\javafx-base\14\javafx-base-14.jar;
C:\.m2\repository\org\openjfx\javafx-controls\14\javafx-controls-14-win.jar;
C:\.m2\repository\org\openjfx\javafx-controls\14\javafx-controls-14.jar;
C:\.m2\repository\org\openjfx\javafx-graphics\14\javafx-graphics-14-win.jar;
C:\.m2\repository\org\openjfx\javafx-graphics\14\javafx-graphics-14.jar,
--add-modules, javafx.base,javafx.controls,javafx.graphics,
-classpath, D:\project\target\classes, org.pkg.pkg.App]
But my project's structure doesn't mention Java module functionality - I didn't have module-info.java file.
Why can't I put all above JARs in the app classpath and be happy?
F.e.:
C:\java\zulu14.29.23-ca-jdk14.0.2-win_x64\bin\java.exe
"-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=59556:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin"
-Dfile.encoding=UTF-8
-classpath D:\project\target\classes;
C:\.m2\repository\org\openjfx\javafx-controls\14\javafx-controls-14.jar;
C:\.m2\repository\org\openjfx\javafx-controls\14\javafx-controls-14-win.jar;
C:\.m2\repository\org\openjfx\javafx-graphics\14\javafx-graphics-14.jar;
C:\.m2\repository\org\openjfx\javafx-graphics\14\javafx-graphics-14-win.jar;
C:\.m2\repository\org\openjfx\javafx-base\14\javafx-base-14.jar;
C:\.m2\repository\org\openjfx\javafx-base\14\javafx-base-14-win.jar
org.pkg.pkg.App
If I'm right and understand Packages and Modules spec correctly
module JARs defined in the classpath treated as unnamed modules
unnamed modules export all their packages, i.e. everything is visible in them
But I get an error
Error: JavaFX runtime components are missing, and are required to run this application
Could someoune please explain me where I'm wrong here, about how Java modules work?
Thanks in advance!
Warning: Although the below shows what you want is possible, placing the JavaFX modules on the class-path is not supported. This means you should place JavaFX on the module-path, even when your own code is non-modular.
You can put JavaFX on the class-path and completely ignore modules1. However, the one caveat is that your main class can no longer be assignable to javafx.application.Application2. The workaround is to create a separate main class that simply launches the JavaFX application. For example:
import javafx.application.Application;
public class Launcher {
public static void main(String[] args) {
// where YourApp.class is replaced with your Application class
Application.launch(YourApp.class, args);
}
}
1. Your can't really ignore modules completely. All code on the class-path ends up in the unnamed module and all the modules in the run-time image (i.e. the JDK/JRE) still function as named modules.
2. This is due to an implementation detail. Java contains code which allows you to launch JavaFX applications without a main method, so long as the main class is assignable to Application. But when it detects that the main class is assignable to Application it checks for javafx.graphics in the boot ModuleLayer—meaning it must be on the module-path—and if not there then it assumes JavaFX is missing.
I created a Java 13 project that uses the modular system, and want to use LITIEngine, a game library made with java 8.
After adding the dependency in Maven using :
<dependency>
<groupId>de.gurkenlabs</groupId>
<artifactId>litiengine</artifactId>
<version>0.4.18</version>
</dependency>
I was expecting to use it as an automatic module, in my module-info.java:
module com.myproject {
require litiengine; // Error: Module litiengine not found.
}
Surprisingly enough, it doesn't seem to be an automatic module, so I grabbed the jar and ran the command jar --file=litiengine-0.4.18.jar --describe-module, and got this weird result:
java.xml.bind jar:file:///D:/WhereverMyJarIs/litiengine-0.4.18.jar/!module-info.class
exports javax.xml.bind
exports javax.xml.bind.annotation
exports javax.xml.bind.annotation.adapters
exports javax.xml.bind.attachment
exports javax.xml.bind.helpers
exports javax.xml.bind.util
requires java.activation transitive
requires java.base mandated
requires java.desktop
requires java.logging
requires java.xml transitive
uses javax.xml.bind.JAXBContextFactory
So, I am supposed to use LITIEngine as java.xml.bind? It doesn't have anything to do with the library I want to use. This makes no sense!
I still tried to require it:
module com.myproject {
requires java.xml.bind; // IntelliJ gives an error: Ambiguous module reference: java.xml.bind
}
Despite the error IntelliJ gives me, i tried to compile my project with Maven, containing a simple HelloWorld.java file:
package com.myproject;
import de.gurkenlabs.litiengine.Game;
public class HelloWorld {
public static void main(String[] args) {
Game.init(args);
Game.start();
}
}
When running mvn compile, the compilation fails (I set maven.compiler.target and maven.compiler.source to 13):
Error:(3,21) java: package de.gurkenlabs.litiengine is not visible
At this point, I just tried to use my project as a nonmodular one, but still use Java 13, so i just deleted the module-info.java, and like that, it works. Great, but I lose the ability to use the module system, which i need to use in my project.
I tried one last thing, I used the LITIEngine jar i grabbed earlier, and removed the module-info.class file in it, by opening the jar file as an archive in 7-zip and deleting that file. Then I added it as a local dependency in maven with:
mvn install:install-file -Dfile=./whereverItIs/litiengine-0.4.18.jar \
-DgroupId=com.myproject.jars -DartifactId=litiengine -Dversion=1 -Dpackaging=jar
And I added it as a dependency:
<dependency>
<groupId>com.myproject.jars</groupId>
<artifactId>litiengine</artifactId>
<version>1</version>
</dependency>
I could then use the library in my module-info.java
module com.myproject {
require litiengine; // No errors this time!
}
And then successfully build it and run it!
So, this proves that this library can work with when imported as an automatic module, but this requires me to edit the jar file and remove the module-info.class in order to make it work, which is very undesirable, because this requires manual action everytime the library receives an update.
The perfect solution would be to be able to ignore the module-info.class file contained inside the jar and make the module system threat it as an automatic module, is there a way to do that?
So I'm adding my requires for module-info.java and finally got my program to load but as soon as tab pane wants to load from jfoenix library this error is thrown.
Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXTabPaneSkin (in module com.jfoenix) cannot access class com.sun.javafx.scene.control.behavior.TabPaneBehavior (in module javafx.controls) because module javafx.controls does not export com.sun.javafx.scene.control.behavior to module com.jfoenix
One way you can try fixing this is by adding the vm option for the required export:
--add-exports javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix
The ideal solution to that would be the jfoenix library to move away from using com.sun.javafx.scene.control.behavior.TabPaneBehavior.
I was able to successfully run every aspect of the jfoenix library thus far. I still have some testing to do in my application to make sure there are no errors hidden but at this moment the following VM options fixed the issue :
--add-exports javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix
--add-exports javafx.controls/com.sun.javafx.scene.control=com.jfoenix
--add-exports javafx.base/com.sun.javafx.binding=com.jfoenix
--add-exports javafx.graphics/com.sun.javafx.stage=com.jfoenix
--add-exports javafx.base/com.sun.javafx.event=com.jfoenix
An alternative to all this module pain is to completely abandon the JPMS and put all libraries (also JavaFX) on the classpath and then start your application via a launcher like this:
class MyAppLauncher {public static void main(String[] args) {MyApp.main(args);}}