简体   繁体   中英

Installed Java 7u9 and Eclipse (Juno) but Eclipse doesn't see JavaFX2

Everywhere that I read, as of Java 7u7, JavaFX2 is bundled with the JRE and JDK. So I am confused as to why when I run Eclipse, it tells me " The import javafx cannot be resolved ".

I have no other JDKs or JREs installed but 7u9, so why would I not be able to see JavaFX2 from Eclipse?

Many thanks :)

Unfortunately, for jdk7u9, Eclipse does not add the jfxrt.jar file from your jre\\lib directory to the project build path libraries when we create a new Java project. You have to do it manually or you can install the e(fx)clipse plugin to Eclipse, which will make your JavaFX development easier :)

Eclipse is following the default settings for the JRE 7u9 default boot classpath (which is to not include jfxrt.jar ). A future JRE version will place jfxrt.jar on the boot classpath so you won't need to manually add the jfxrt.jar file to project build path libraries. You can track this JRE feature .

Adding jfxrt.jar to the project build path will enable eclipse to find it and permit you to develop and execute your code from within eclipse. However, when you deploy your software, it will no longer be able to find jfxrt.jar unless you also place it on the classpath. This gets messy as you have to muck around finding the location of the jdk / jre and searching inside for the location of jfxrt.jar .

From what I understand, the long term plan is to move jfxrt.jar from the lib folder in the jre to the lib/ext folder. This will place it somewhere where it is found by default without needing to add stuff to your classpath. Unfortunately this is not likely to happen before Java 8 is released!

Meanwhile, the easiest solution appears to be to use the bundled javafxpackager tool to create your jar file, rather than the jar tool. There is also an ant based solution, but I'm not familiar with it. The packager will create your jar file, and insert a launcher class that finds jfxrt.jar and dynamically adds it to your app's classpath at runtime. It also complains if the jre or installed javafx is too old and prompts the user to download a newer version. Then it calls your application via a class you specified on the command line. (usually the class with your main() method).

It works for both native javafx applications and plain old Swing applications. If you had extra stuff in the manifest of your jar file, such as another ClassPath entry, you can specify that on the command line as well, for inclusion in the new jar file.

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