英文:
Getting "Module javafx.controls not found" error Java Eclipse IDE
问题
我正在使用Eclipse IDE 2020-03版本与Java。我尝试使用FXML,在网上查看了一些教程并按照它们的步骤操作。但我仍然遇到以下错误:
在引导层初始化期间发生错误
java.lang.module.FindException:找不到模块javafx.controls
我在谷歌上寻求帮助。有很多人遇到了相同的问题,并且能够解决这个问题。但是我看到的所有解决方法都是他们要么使用NetBeans IDE,要么使用IntelliJ。有人有Eclipse的解决方案吗?任何帮助都将不胜感激。
我遵循了这个教程 -> https://www.youtube.com/watch?v=bC4XB6JAaoU 。以下是我目前的情况:
从Market Place安装的e(fx)clipse 3.6.0
"Java Build Path"包含库(我之前使用的是15.0,然后切换回了14.0,但错误仍然存在)
"Java Build Path"包含库(我之前使用的是15.0,然后切换回了14.0,但错误仍然存在)
VM参数具有以下行(指向库位置):--module-path "C:\Users\my_name\Documents\Scene Builder\openjfx-14.0.1_windows-x64_bin-sdk\javafx-sdk-14.0.1\lib" --add-modules javafx.controls,javafx.fxml
我尝试在eclipse.ini文件中使用"-clean",但没有帮助。实际上,当我尝试创建新的简单项目并再次按照所有步骤操作时,Java甚至不认识JavaFX。
谢谢!
英文:
I am using Eclipse IDE 2020-03 version with Java. I am trying to use FXML, checked some tutorials and steps online and followed them. But I am still getting the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
I googled for help. There are a lot of people having the same issue and were able to resolve this issue. But all I've seen is they are using either NetBeans IDE or IntelliJ. Does anybody have solution for Eclipse? Any help would be appreciated.
I followed this tutorial -> https://www.youtube.com/watch?v=bC4XB6JAaoU . Here is what I currently have:
e(fx)clipse 3.6.0 installed from Market Place
"Java Build Path" contains libraries (I was on 15.0, then switched back to 14.0 but the error still exist)
"Java Build Path" contains libraries (I was on 15.0, then switched back to 14.0 but the error still exist)
VM Arguments has the following line (pointing library location): --module-path "C:\Users\my_name\Documents\Scene Builder\openjfx-14.0.1_windows-x64_bin-sdk\javafx-sdk-14.0.1\lib" --add-modules javafx.controls,javafx.fxml
I tried to use "-clean" in eclipse.ini file but it didn't help. Matter fact, when I tried to create new simple project and follow all the steps again, Java doesn't even recognize JavaFX.
Thanks!
答案1
得分: 6
我也遇到了同样的问题。我的问题源于一个原因,就是由于某种原因,javafx sdk库位于构建配置中的模块路径下,而不是类路径下。将JavaFX SDK从模块路径移动到类路径后,错误就被修复了。
如果你的情况也是这样,你可以通过以下步骤来修复:只需右键单击javaFX项目文件夹->构建路径->配置构建路径->选择JavaFX SDK->移除库->选择类路径->添加库->用户库->选择库->应用。
一个非常好的教程可以帮助我进行设置,可以在这里找到。
希望这能帮到你。
英文:
I also encountered the same issue. My problem originated from the fact that for some reason the javafx sdk library was located under module path instead of the class path in the build configurations. After moving the JavaFX SDK from the module path to the class path the error was fixed.
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.
Essentially it should look like this:
A great tutorial to help me set up was found on here
Hope that this helps
答案2
得分: 1
感谢大家!我成功让它运行起来了。我安装了最新的Eclipse IDE 2020-09 版本:2020-09 (4.17.0) 编译编号:20200910-1200。我重新安装了jdk15.0.1,并将其放在了Modulepath下而不是Classpath下,现在它可以正常工作。
英文:
Thanks everyone! I managed make it work. I installed the latest Eclipse IDE 2020-09
Version: 2020-09 (4.17.0)
Build id: 20200910-1200
Installed jdk15.0.1 back and placed it under Modulepath not under Classpath and it is working now.
答案3
得分: 1
如果您使用的是更新版本,则应将所有内容放在 ModulePath 中。
java -version
openjdk版本 "17.0.1" 2021-10-19
OpenJDK运行时环境(构建17.0.1+12-39)
OpenJDK 64位服务器虚拟机(构建17.0.1+12-39,混合模式,共享)
英文:
If you are using the newer versions you should put everything in the ModulePath.
java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
答案4
得分: 0
JavaFX不再是JDK的一部分。因此请将其视为普通的依赖项。与其他Maven库一样:`https://mvnrepository.com/artifact/org.openjfx`
我正在使用OpenJDK 11,以下是我的pom.xml文件示例:`https://pastebin.com/6hjDtaiw`
`javafx-maven-plugin`用于获取特定于平台的库文件(.dll用于Windows,.so用于Linux...)
`javafx-controls`用于标签、按钮和其他JavaFX UI元素。
不要直接启动您的Application类。否则,您将会得到以下错误:
`错误:缺少JavaFX运行时组件,需要运行此应用程序`
只需编写一个额外的类来调用您的Application类的“main”方法。
英文:
JavaFX isn't part of the JDK anymore. So treat it like a normal dependency. Like any other maven library too: https://mvnrepository.com/artifact/org.openjfx
I'm using OpenJDK 11 and here is an example of a my pom.xml File: https://pastebin.com/6hjDtaiw
The javafx-maven-plugin
is to get the platform specific libraries (.dll for Windows, .so for linux ...)
javafx-controls
is for the Labels, Buttons, and other JavaFX UI elements
And do not start your Application Class directly. Otherwise you'll get the following error:
Error: JavaFX runtime components are missing, and are required to run this application
Just write an additional class to call the "main" method of your Application class.
答案5
得分: 0
我知道这个旧帖子,如果还有人遇到这个问题,那么尝试遵循以下任一解决方案,这些解决方案对我有效。
1-> 将 JavaFX 和 JavaFX SDK 都放在模块路径下。
2-> 或者您可以在虚拟参数中添加以下命令。
--module-path "路径\到\javafx-sdk-15.0.1\lib" --add-modules JavaFX.controls,JavaFX.fxml
这里的模块路径是您外部 JAR 文件的位置。
希望这对您有用。
英文:
I know this old post, if anyone still facing this problem, then try to follow any one of these solutions that work for me.
1-> put both JavaFX and JavaFX SDK under the module path.
2-> or you can add this command inside the virtual arguments.
--module-path "\path\to\javafx-sdk-15.0.1\lib" --add-modules JavaFX.controls,JavaFX.fxml
here module path is the location of your external JAR file.
Hope this work for you.
答案6
得分: -1
我尝试了上述所有的解决方案,但是都没有起作用,然后我只是创建了一个 module-info.java 文件,然后我的程序开始工作了。只需在项目上右键单击,然后转到 >> 配置 >> 创建 module-info.java。
英文:
i tried all the above solutions but nothing work, then I just creat module-info.java file and my program start working.
just right click on your project and goto>>configure>>creat module-info.java
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论