How to Fix the Access Restriction Error When Using JavaFX in JRE 8

MD Aminul Islam Feb 15, 2024
How to Fix the Access Restriction Error When Using JavaFX in JRE 8

On some IDE that contains a lower version of JRE, we get an Access restriction error when we try to compile our JavaFX code. This happened because some lower version of JRE doesn’t support the JavaFX library.

It shows that error when we try to include the JavaFX library externally.

This article will discuss how to fix the Access restriction error when using JavaFX in JRE 8. This error mainly occurs in Eclipse IDE; our solution is mainly based on Eclipse.

Fix the Access restriction Error When Using JavaFX in JRE 8

We mainly include our JavaFX library by attaching the JAR file to our project. However, there is a problem with Eclipse.

It disallows access to classes inside the JAR file in the directory of jre/lib/ext. So, when you write applications in JavaFX 8, you may think the jfxrt.jar is available in the location of lib/ext on your IDE.

Let’s discuss the minimal fix to this problem to allow access to classes in the JAR file.

  • First, you need to right-click on the Project option. Then you have to bring up the project’s Properties dialog.
  • After that, you have to select the Build Path on the left side and select the Libraries.
  • Now, you can see an option named JRE System Library. Open it, and the Access Rules option will be found.

    access restriction javafx image 1

  • Now click on that entry and click Edit > Add. You can see the option Resolution.

    access restriction javafx image 2

  • Choose Accessible, and then under the Rule Pattern, enter javafx/**.

    access restriction javafx image 3

  • Lastly, click on OK and exit all dialogs.

Now, you can check whether your problem is solved. It will be better to use an IDE containing an updated JRE version like NetBeans.

NetBeans contains necessary plugins that allow you to create and compile JavaFX programs automatically. It also contains JavaFX Scene Builder, through which you can create the User Interface for the application by just dragging and dropping.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - Java JavaFX