Getting "Module javafx.controls not found" error Java Eclipse IDE - java

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)
javafs-sdk jar files
"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!

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

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.
enter image description here

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)

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.

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.

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

Related

Can't integrate SWT with JavaFX under "Zulu" JDK 11

We want to use both SWT and JavaFX in an Eclipse plugin within our RCP application. Unfortunately, we're experiencing problems integrating SWT with JavaFX under Java 11. The build environment uses e(fx)clipse 3.5. We're developing against the Community edition of Azul Systems' "Zulu" JDK 11, bundled with Azul's version of OpenJFX.
Formerly, we developed under Java 8. At that point, our build used a compile-time class path referring to jfxswt.jar, which lived in the jre/lib directory of the JDK. We didn't use any special class path settings at run-time.
We are now trying to move to Java 11. There, this JAR has become javafx-swt.jar and lives in the lib directory of the JDK. It no longer seems to be enough to set the class path to refer to this JAR at compile time: it seems to be necessary to do so at run time too. If we don't do this, we get an error (java.lang.NoClassDefFoundError: javafx/embed/swt/FXCanvas).
As a test, we experimentally embedded javafx-swt.jar within the JAR implementing our Eclipse plugin. We then referred to it in that plugin's .classpath file, and the code worked as expected. Unfortunately, we can't embed the JAR this way for legal and other reasons.
A note on Java modules: javafx.swt does not show up in the output when we issue the --list-module command. We tried running the application using parameters -p /path/to/JDK/lib/javafx-swt.jar --add-modules javafx.swt, but this doesn't seem to solve the problem.
My question: Is there a way to set up the class or module path to allow our Eclipse plugin to find this library in the JRE? Any solution would have to work with whatever JRE the code happens to be run against (I think it is all right to assume lib/javafx-swt.jar will live in that JRE).
Would it help to use a separately-downloaded version of OpenJFX rather than the copy of OpenJFX in our JDK?
Very many thanks ☺

JavaFX not imported with Java 8

I'm doing a Java project which involves JavaFX. I'm using Eclipse Oxygen with Java 8 (java-8-openjdk-amd64) and I installed the Eclipse plugin e(fx)clipse.
I don't understand why this project has two errors:
The project was not built since its build path is incomplete. Cannot find the class file for javafx.geometry.Point2D. Fix the build path then try building this project
and
The type javafx.geometry.Point2D cannot be resolved. It is indirectly referenced from required .class files
I searched on StackOverflow for similar problems, and tried some settings changes but nothing solved my problem.
I tried to change the access rules in the Build Path of my project: Build Path > Configure Build Path > Libraries > JRE System Library > Add a new rule
I added different rules: javafx/**, changed it to **/javafx/** but nothing changed.
This project works well in Windows, I opened it with Eclipse on Windows and everything works fine.
Do you have an idea on how to solve this problem?
EDIT: Accepted answer: $ sudo apt install openjfx
It looks like you haven't installed JavaFX. Because some parts of JavaFX are not compatible with the distributions open source licenses, it often is not part of the packages shipped by default.
If you're using Ubuntu, you can install it using sudo apt install openjfx.
For further reading have a look at JavaFX and OpenJDK.

can not use javafx on intellij idea

I have problem importing import "javafx.util.Pair" into my program.
after searching the net I've found this answer cannot resolve symbol javafx.application in IntelliJ Idea IDE and I've installed desired jar file but still I've problem to import.
this is what I face to when open java jdk.
I don't know the why the "jfxrt.jar" is different.
note the black arrow on the folder icon
open the File | Project Structure dialog, there under Platform Settings select SDKs and then your JDK 1.8. On the right you then see all the jars that make up the classpath to your SDK. Make sure that your jfxrt.jar is in that list, if not, you can add it by clicking the '+' button at the bottom.
Update May 2020
JavaFX is no longer part of the Oracle or OpenJDK default distributions. Instead it is available as a seperate library or module set.
For instructions on using JavaFX in your application, see the documentation at:
https://openjfx.io
For instructions on working with a modern JavaFX installation and Idea, also see the related question:
IntelliJ can't recognize JavaFX 11 with OpenJDK 11
You don't need to "install the desired jar" (whatever that means).
You don't need to do that for JavaFX. You should not do anything explicitly with jfxrt.jar either in the filesystem or by adding it to a project classpath. If doing something on the filesystem, that is especially bad as jfxrt.jar is not made to be standalone and requires related native libraries shipped with the JDK in order to work.
The JavaFX code should be part of the JDK installation you are using. Perhaps you are using a Java version below 8 or an OpenJDK implementation that does not include JavaFX. If so, then install the Oracle JDK 8+ and set idea to use it. Everything should just work then and all of related JavaFX imports will resolve.

Java Fatal Error: Unable to find package java.lang in classpath or bootclasspath

I'm getting this error
Error:java: Fatal Error: Unable to find package java.lang in classpath or bootclasspath
in IntelliJ when I try to build/compile any project. Something that should be stated here is that NetBeans, Eclipse and even the javac command line can compile, build, and execute the same project without errors. This is why I suspect that the problem lies with IntelliJ, all other IDEs work well.
In IntelliJ I already:
Restarted, reinstalled
Invalidate Caches / restarted
Deleted / readded the JDK in Project JDK
Deleted / readded the JDK in Platform Settings
Rebuild / recompile
In Windows I already:
Deleted / Reinstalled Java SDK
Deleted / Readded the JAVA_HOME, PATH and CLASSPATH on System Variables
Tried the above on User Variables
Deleted and reinstalled IntelliJ IDEA
I already seached for issues like this on the Internet, here on Stack Overflow I found:
Question #1 | Question #2 | Question #3 | Question #4 | Question #5
And 30+ sites, and tried every answer...
Here you can see my IntelliJ Project Structure the last time that I tried to build/compile
I was using Java 1.8 when I got this error, after some hours, I installed Java 1.7 and the project worked fine. Maybe IntelliJ doesn't support Java 1.8?
Anyway, it would be great if anyone knew a way to make Java 1.8 work with IntelliJ.
I just spent quite few hours on this and found a solution which might work for you as well. IntelliJ seems to have a bug which expects the JDK to be in a different directory than is specified. I followed these steps:
open intelliJ, click help -> show log in explorer
modify build-log/build-log.xml and change <priority value="info" /> to <priority value="debug" />, you may have to run the editor as an administrator
run the compilation which fails with "Error:java: Fatal Error: Unable to find..."
open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong
In my case the JDK is included in D:\Development\software\jdk1.8.0_20, while the log points to C:\Users\Vladimir\Development\software\jdk1.8.0_20
I fixed the issue by copying my JRE to the place which is expected in the log. And just like in your case this seems to only happen with JDK 1.8.
The problem comes from IntelliJ bug (existing at least in version 14).
It happens when your JDK directory is under the user profile directory. For example, JDK located in this directory (for Windows):
C:\Users\myuser\jdk1.8.0_20
will be stored in IntelliJ internal configuration (file 'jdk.table.xml') as:
$USER_HOME$\jdk1.8.0_20
But your %USER_PROFILE% environment variable could point at some other (non default) location. Then IntelliJ will look at the wrong directory.
Possible fix:
Install your JDK at different directory, which is outside your profile directory. Like:
C:\Programs\jdk1.8.0_20
Then register this JDK for use in your IntelliJ project settings.
I encountered this on Arch Linux 4.16.13 with IntelliJ 2018.1.4 after importing a Java project using Gradle. I made sure that there is a registered JDK in "Project Settings" -> "Project" but IntelliJ was unable to find the classes from the JDK, java.util.List for example.
The solution was to add a new JDK entry at the same path as the existing JDK (/usr/lib/jvm/java-8-openjdk in my case). This will cause IntelliJ to put the files under jre onto the classpath whereas with the old JDK entry, only the files under lib were on the classpath.
Had the same problem. Simple fix to others in case the other answers are complex.
Go to File -> Project Structure
Under Project SDK, choose new and add another JDK.
The default use in my case was 1.8 that was of build 181. I choose the 1.8.0_192 I had recently downloaded.
After applying, the project loads itself.
When I re-ran the test, it works!
If this problem occurs when importing a project in netbeans then try to create a new project then check the properties of your new created project and match those properties with the project that you imported in my case there was a difference between target of android package version.
From what I understood, debugging for hours, the problem is with the location where the jdk1.8 gets installed(/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home), instead of under System/Library).
So the following has to be done to fix in intellij
1. For an existing project, right click and select module settings, and SDK and add 1.8 as a version.
2. Using a terminal go to ~/Library/Preferences//options/. Remove the old JDK specific lines in jdk.table.xml. Update the default version in project.default.xml
Clean you project in intellij and build. It should use the new jdk and sync.

how to solve a groovy/grails tool suite reference?

I've been working on my desktop computer which has openjdk 7.
When I copy a Grails project onto my laptop, which has Oracle's JDK v7, I'm having a problem with the classpath.
I've checked the classpath and everything seems fine.
Here's the text that GGTS shows:
The archive: /usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar which is
referenced by the classpath, does not exist
I set the JAVA_HOME inside /etc/profile.
I installed gvm in order to make easier Groovy and Grails setup.
I hope you could help me
:)
I then went to the RUN menu option at the top and selected run configuration
It was on : Grails \ {Myproject} (run-app)
On the right for this run-app there is JRE options
under JRE ensure you have the same JRE defined as project in this case 1.6
I'm guessing that your JRE reference in your project is bad. Is your desktop windows and your laptop a mac or linux (or vice versa)?
Try these things:
Does the /usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar path exist on the broken system?
Can you create other kinds of projects on the broken system?
Can you create a new Grails project from scratch inside of the broken GGTS?
What happens if you run Grails -> Refresh dependencies on the project?

Categories

Resources