Eclipse uses its own integrated Java compiler. You do not need to set up a JDK for Eclipse. It is only necessary to set up a Java JRE to run applications you write.
Every Eclipse workspace needs its own settings. Projects in this workspace inherit these workspace settings. But you can set up every project on its own.
Table of content
- Add JRE api documentation and source code to use it within Eclipse
- Add JavaFX api documentation and source code to use it within Eclipse
- Eclipse & the JavaFX 8 library access restriction bug
Add JRE api documentation and source code to use it within Eclipse
To have a look at the original JRE library source code and to quick access the Javadoc documentation of the JRE libraries do the following steps.
preferences -> Java -> Installed JREs choose your JRE and click on edit.
Mark the highlighted libraries and click on
Choose the location of the JDK-doc documentation archive file, browse within the archive to the folder called
api and click validate to proof if Eclipse can find the entry point of the documentation.
Select the location of the JDK-doc file. Mine is within my workspace in a project called JavaSE8 resources.
Now lets attach the source code to this libraries.
My JRE api source code archive is within my workspace.
Add JavaFX api documentation and source code to use it within Eclipse
For JavaFX do the same steps as above but now add docs and sources for the highlighted
Choose the JavaFX api doc archive and navigate to the folder
api. Then validate to make Eclipse can find the entry point for the documentation.
At last select source attachment to add the JavaFX source archive.
Choose the path to your JavaFX source archive. Mine is within my workspace in a special project called JavaSE8 resources.
Eclipse and the JavaFX 8 library access restriction bug
Your situation: You want to create a JavaFX GUI with JRE 1.8. And in Eclipse a JavaFX import is not possible.
Problem explanation: JavaFX is not part of the base Java SE 8 API. Because of Eclipse strictness, you can’t access it. The bug is: JavaFX is already in Java SE 8 standard library. You can’t import it a second time.
Hint: Eclipse has its own Java compiler. A dedicated JDK is not necessary when working with Eclipse. The Java JRE you have installed on your computer causes the problem. The JRE runs after you have compiled your app with the build in Eclipse compiler. Eclipse also uses the JRE to check dependencies and much more.
Your error message could look like this:
Access restriction: The type 'Application' is not API (restriction on required library 'C:\Program Files\Java\jre1.8.0_191\lib\ext\jfxrt.jar')
Some solutions don’t work:
- Trying to add
jfxrt.jarto the Java build path doesn’t help. Because it’s already in there.
- Trying to loosen the severity level of the Java compiler errors/warnings doesn’t help.
Workaround: The fastest workaround (but no solution) is to set a loosen access rule to your build path:
project properties -> Java Build Path -> Libraries: edit the
'Access rules' for your current JRE.
javafx/** as an accessible rule.
After adding the accessible rule.
Alternate Solution: You can also use an “Alternate JRE” as system library, to loosen this restriction.