Using JavaFX in JRE 8, “Access restriction” error

2019-01-03 23:30发布

When trying to use javafx related classes in my new java 8 project I get an access restriction error from eclipse. So far the only 'solution' I've been able to find is to tell eclipse to ignore the access restriction, but I am not satisfied with that. An example of the error:

Access restriction: The type Pane is not accessible due to 
restriction on required library C:\Program Files\Java\jre8_0\lib\ext\jfxrt.jar

I'm using Eclipse Kepler with the Eclipse JDT patch for java 8.

This seems to be an issue related to the fact that JavaFX is not a part of the JavaSE execution environment.

I am now toughly confused as according to http://en.wikipedia.org/wiki/JavaFX javaFX is a part of the JavaSE. Is it possible that Eclipse is not recognizing that it is a part of the javaSE?

11条回答
来,给爷笑一个
2楼-- · 2019-01-03 23:52

I've resolved this problem by some careful use of the Eclipse project's build path.

  • Bring up the properties of the you application project and select the 'Build Path' section.
  • Add the jre8_0\lib\ext\jfxrt.jar as an "External JAR file" in the 'Libraries' tab.
  • In the 'Order/Export' tab ensure that this jfxrt.jar is first in the list.

What this doing is making Eclipse see the jfxrt.jar as just a regular 3rd party JAR file. The order is important so that this takes precedence over the entry in the JRE system library. It's the same actual JAR file, but Eclipse is seeing it differently.

You may wish to alter any run configurations so it doesn't use the 'Exported' version of the jfxrt.jar; however in practical terms this won't make a difference.

I've done this with Java8 and Eclipse Luna; but the principal would I am sure work with any combination of Java and Eclipse.

查看更多
ら.Afraid
3楼-- · 2019-01-03 23:56
  • go to the build path of the current project

under Libraries

  • select the "JRE System Library [jdk1.8xxx]"
  • click edit
  • and select either "Workspace default JRE(jdk1.8xx)" OR Alternate JRE
  • Click finish
  • Click OK

enter image description here

Note: make sure that in Eclipse / Preferences (NOT the project) / Java / Installed JRE ,that the jdk points to the JDK folder not the JRE C:\Program Files\Java\jdk1.8.0_74

enter image description here

查看更多
可以哭但决不认输i
4楼-- · 2019-01-03 23:58

As James_D already suggested I added access rules to my classpath file. I uninstalled the e(fx)clipse plugin for the time being because it has a css validation bug (see How to disable css warning "Unknown property" in Eclipse Mars?).

Here is my entry in the classpath file for the JRE container:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.‌​launcher.StandardVMType/JavaSE-1.8">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes> 
    <accessrules>
        <accessrule kind="accessible" pattern="javafx/**"/>
        <accessrule kind="accessible" pattern="com/sun/javafx/**"/>
    </accessrules>
</classpathentry>
查看更多
倾城 Initia
5楼-- · 2019-01-03 23:59

I had the same problem. I used James_D 's solution but his exact solution did not work for me. But using **/javafx/** instead of javafx/** solved the problem for me. Hope that helps.

PS: I would post this as a comment under James_D 's solution but I just registered and did not have enough "reputation" to do so.

查看更多
相关推荐>>
6楼-- · 2019-01-04 00:04

Step-1: Navigate to your jfxrt.jar. C:\Program Files\Java\jre1.8.0_111\lib\ext

Step-2 Copy the file jfxrt.jar

Step-3: Go to Eclipse,Create a new folder like this: [Creating folder name lib to put our jfxrt.jar file][2] [2]: https://i.stack.imgur.com/YsJ5S.png

Step-4: Select the lib folder and press CTRL+V to paste the jfxrt.jar [Paste your jfxrt.jar][1] [1]: https://i.stack.imgur.com/Ljogu.png

Step-5: Right click on jfxrt.jar and set as Build Path.

查看更多
登录 后发表回答