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

时间:2022-03-28 17:01:52

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".

在我阅读的任何地方,如Java 7u7, JavaFX2都与JRE和JDK绑定在一起。所以我很困惑为什么当我运行Eclipse时,它告诉我“import javafx不能被解析”。

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

除了7u9,我没有其他的jdk或JREs,那么为什么我不能从Eclipse中看到JavaFX2呢?

Many thanks :)

非常感谢:)

2 个解决方案

#1


8  

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 :)

不幸的是,对于jdk7u9, Eclipse不添加jfxrt。当我们创建一个新的Java项目时,从jre\lib目录到项目构建路径库的jar文件。您必须手动操作,或者您可以将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). 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.

Eclipse正在跟踪JRE 7u9默认启动类路径(不包括jfxrt.jar)的默认设置。未来的JRE版本将放置jfxrt。在引导类路径上的jar,这样您就不需要手动添加jfxrt了。jar文件到项目构建路径库。您可以跟踪这个JRE特性。

#2


2  

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.

添加jfxrt。jar到项目构建路径将使eclipse能够找到它并允许您在eclipse中开发和执行您的代码。但是,当您部署您的软件时,它将不再能够找到jfxrt。除非你把它放在类路径上。这变得很麻烦,因为您必须仔细查找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. 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!

据我所知,长期计划是将jfxrt移动。从jre的lib文件夹到lib/ext文件夹。这将把它放置在默认情况下,而不需要向类路径添加内容。不幸的是,这在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. 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).

与此同时,最简单的解决方案似乎是使用绑定的javafxpackager工具来创建jar文件,而不是jar工具。还有一个基于ant的解决方案,但是我不熟悉它。packager将创建您的jar文件,并插入一个查找jfxrt的启动程序类。jar并在运行时动态地将其添加到应用程序的类路径中。它还会抱怨jre或安装的javafx太旧,并提示用户下载更新的版本。然后通过在命令行上指定的类调用您的应用程序。(通常是使用main()方法的类)。

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.

它适用于原生javafx应用程序和普通旧式Swing应用程序。如果在jar文件的清单中有额外的内容,比如另一个类路径条目,您也可以在命令行中指定,以便将其包含在新的jar文件中。

#1


8  

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 :)

不幸的是,对于jdk7u9, Eclipse不添加jfxrt。当我们创建一个新的Java项目时,从jre\lib目录到项目构建路径库的jar文件。您必须手动操作,或者您可以将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). 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.

Eclipse正在跟踪JRE 7u9默认启动类路径(不包括jfxrt.jar)的默认设置。未来的JRE版本将放置jfxrt。在引导类路径上的jar,这样您就不需要手动添加jfxrt了。jar文件到项目构建路径库。您可以跟踪这个JRE特性。

#2


2  

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.

添加jfxrt。jar到项目构建路径将使eclipse能够找到它并允许您在eclipse中开发和执行您的代码。但是,当您部署您的软件时,它将不再能够找到jfxrt。除非你把它放在类路径上。这变得很麻烦,因为您必须仔细查找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. 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!

据我所知,长期计划是将jfxrt移动。从jre的lib文件夹到lib/ext文件夹。这将把它放置在默认情况下,而不需要向类路径添加内容。不幸的是,这在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. 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).

与此同时,最简单的解决方案似乎是使用绑定的javafxpackager工具来创建jar文件,而不是jar工具。还有一个基于ant的解决方案,但是我不熟悉它。packager将创建您的jar文件,并插入一个查找jfxrt的启动程序类。jar并在运行时动态地将其添加到应用程序的类路径中。它还会抱怨jre或安装的javafx太旧,并提示用户下载更新的版本。然后通过在命令行上指定的类调用您的应用程序。(通常是使用main()方法的类)。

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.

它适用于原生javafx应用程序和普通旧式Swing应用程序。如果在jar文件的清单中有额外的内容,比如另一个类路径条目,您也可以在命令行中指定,以便将其包含在新的jar文件中。