Using JavaFX in JRE 8
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 FilesJavajre8_0libextjfxrt.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?
From the Eclipse Point of view the error is totally correct because JavaFX is coming from the extension classpath and is not available on ALL Java8 VMs (eg ibm!).
As outlined you can suppress those warnings by add access-rules or IMHO the best solution is to install e(fx)clipse which does this automatically for you and beside that even provides you tooling for JavaFX CSS and FXML.
You can grab an all in one package from http://efxclipse.bestsolution.at/install.html
I'm going to add one more answer here, just to provide what I think is the most minimal approach. In my Eclipse setup, I have e(fx)clipse installed, which provides one fix for this, as well as providing many useful development features that you will almost certainly want if you are writing JavaFX applications. This is probably the most practical approach. If for some reason you don't want that plugin, the solution outlined in this answer will fix the problem with the least amount of other side effects.
As pointed out in other answers, Eclipse, by default, disallows access to classes in jar files in the jre/lib/ext directory, as these are not guaranteed to be present on all Java platforms. If you are writing a JavaFX 8 application, you are assuming you are on a platform where jfxrt.jar is available in the lib/ext location.
So the minimal fix for this is to allow access to the classes in this jar file (and only in this jar file). To do this, right-click on the project and bring up the project properties dialog. Select "Build Path" in the left pane, and select the "Libraries" tab. You will see a "JRE System Library" entry. Expand that entry, and you will see an "Access Rules" subentry:
Select the "Access Rules" entry and click "Edit". Click "Add".
Under "Resolution", choose "Accessible", and under "Rule Pattern", enter javafx/**
:
Click OK to exit all the dialogs.
This setting will allow access to all the classes in any packages beginning javafx.
, but will preserve the rule on the ext folder for all other classes, and is "minimal" in that sense.
Again, what you probably really want to do is to install the e(fx)clipse plugin, but to my knowledge this is the solution with the least side effects on your Eclipse setup.
I resolved the problem by removing and readding the JDK to the build path. Don't ask me why this works, though.
链接地址: http://www.djcxy.com/p/65926.html上一篇: Google地图和JavaFX:点击JavaFX按钮后在地图上显示标记
下一篇: 在JRE 8中使用JavaFX