简体   繁体   中英

Eclipse - 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 ..\\jre\\lib\\rt.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:

  1. 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.
  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM