External jars need to be manually added

I had a question that was answered with adding jfxrt.jar to standard Eclipse build path.

I followed the suggestion, adding the jfxft.jar as an External Jar on the jdk1.7.0_10.jdk JRE i have installed (under Eclipse > Preferences > Java > Installed JREs).

But when I import "javafx.application.Application"

It errors with:

Access Restriction: The type Application is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/jre/lib/jfxrt.jar

There are posts on this such as Access restriction: Is not accessible due to restriction on required library ..jrelibrt.jar

I can fix this possibly by the suggestions in that thread (though I'm not convinced they are good solutions).

Or I found a better solution of adding the External Jar directly to the project: - go to the JRE and remove the External Jar as setup above - Open project properties and go to Java Build Path - Go to Libraries tab - Add External JARS... and choose exactly the same jfxrt.jar

No access restrictions now!

Why does it work one way but not the other? The advantage of adding directly to the JRE configuration is that it only needs to be done once.

Thanks,

Hank


I would not recommend adding JARs to the JRE configuration like that, it's just too easy to forget they are there and that can lead to confusing behavior if you don't expect that particular JAR to be on the build path for a particular project. Also, what happens if one project wants to use a different version of the library?

There are at least 2 other options that I would consider:

  • Define a User Library for JavaFX and then include the User Library on the projects that need it. You still would have to add the User Library to each project that needs it, but that's not such a big deal IMO, as it only has to be done once for each project.
  • Create a separate project to contain the JAR(s), call it something like "JavaFX Libs." Add the JARs to its build path and make sure to export them on the Order and Export tab; then add "JavaFx Libs" project as a dependency for whatever projects need it.
  • 链接地址: http://www.djcxy.com/p/12824.html

    上一篇: Java swing在Debian 9.2中不起作用

    下一篇: 外部罐子需要手动添加