简体   繁体   English

安装了Java 7u9和Eclipse(Juno),但Eclipse没有看到JavaFX2

[英]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. 我读到的所有地方,从Java 7u7开始,JavaFX2都与JRE和JDK捆绑在一起。 So I am confused as to why when I run Eclipse, it tells me " The import javafx cannot be resolved ". 所以我很困惑为什么当我运行Eclipse时,它告诉我“ 导入javafx无法解析 ”。

I have no other JDKs or JREs installed but 7u9, so why would I not be able to see JavaFX2 from Eclipse? 我没有安装其他JDK或JRE但是7u9,那么为什么我无法从Eclipse中看到JavaFX2?

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. 不幸的是,对于jdk7u9,当我们创建一个新的Java项目时,Eclipse不会将jre\\lib目录中的jfxrt.jar文件添加到项目构建路径库中。 You have to do it manually or you can install the e(fx)clipse plugin to Eclipse, which will make your JavaFX development easier :) 您必须手动执行此操作,或者您可以将e(fx)clipse插件安装到Eclipse,这将使您的JavaFX开发更容易:)

Eclipse is following the default settings for the JRE 7u9 default boot classpath (which is to not include jfxrt.jar ). Eclipse遵循JRE 7u9默认引导类路径的默认设置(不包括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. 未来的JRE版本会将jfxrt.jar放在引导类路径中,因此您无需手动将jfxrt.jar文件添加到项目构建路径库中。 You can track this JRE feature . 您可以跟踪此JRE功能

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. jfxrt.jar添加到项目构建路径将使eclipse能够找到它并允许您在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. 但是,当您部署软件时,它将无法再找到jfxrt.jar除非您也将它放在类路径上。 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 . 这会变得混乱,因为你必须找到jdk / jre的位置并在里面搜索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. 据我所知,长期计划是将jfxrt.jarjrelib文件夹移动到lib/ext文件夹。 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! 不幸的是,在Java 8发布之前不太可能发生这种情况!

Meanwhile, the easiest solution appears to be to use the bundled javafxpackager tool to create your jar file, rather than the jar tool. 同时,最简单的解决方案似乎是使用捆绑的javafxpackager工具来创建jar文件,而不是jar工具。 There is also an ant based solution, but I'm not familiar with it. 还有一个基于ant的解决方案,但我不熟悉它。 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. 打包器将创建您的jar文件,并插入一个找到jfxrt.jar的启动器类,并在运行时将其动态添加到应用程序的类路径中。 It also complains if the jre or installed javafx is too old and prompts the user to download a newer version. 如果jre或安装的javafx太旧并且提示用户下载更新的版本,它也会抱怨。 Then it calls your application via a class you specified on the command line. 然后它通过您在命令行上指定的类调用您的应用程序。 (usually the class with your main() method). (通常是带有main()方法的类)。

It works for both native javafx applications and plain old Swing applications. 它适用于本机javafx应用程序和普通的旧Swing应用程序。 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. 如果jar文件的清单中有额外的东西,例如另一个ClassPath条目,您也可以在命令行中指定它,以包含在新的jar文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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