如何在 Eclipse 中使用 JavaFX 2 SDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8241525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use JavaFX 2 SDK in Eclipse?
提问by Jonas
I have installed JavaFX 2.0 SDK and now I would like to do an JavaFX application with Eclipse. But how can I use the javafx.*
classes in Eclipse?
我已经安装了 JavaFX 2.0 SDK,现在我想用 Eclipse 做一个 JavaFX 应用程序。但是我怎样才能javafx.*
在 Eclipse 中使用这些类呢?
The official JavaFX Eclipse pluginseem to be for JavaFx 1.2 and outdated.
在官方的JavaFX Eclipse插件似乎是为JavaFX 1.2和过时。
When I try to install e(fx)clipse plugin, I get this error:
当我尝试安装e(fx)clipse 插件时,出现此错误:
Cannot complete the install because one or more required items could not be found.
Software being installed: efxclipse 0.0.8.201111131640 (at.bestsolution.efxclipse.feature.feature.group 0.0.8.201111131640)
Missing requirement: Eclipse DI integration for JavaFX 0.0.8.201111131640 (at.bestsolution.efxclipse.runtime.di 0.0.8.201111131640) requires 'bundle org.eclipse.e4.core.contexts 0.9.0' but it could not be found
Cannot satisfy dependency:
From: efxclipse 0.0.8.201111131640 (at.bestsolution.efxclipse.feature.feature.group 0.0.8.201111131640)
To: at.bestsolution.efxclipse.runtime.feature.feature.group [0.0.8.201111131640]
Cannot satisfy dependency:
From: FX Runtime 0.0.8.201111131640 (at.bestsolution.efxclipse.runtime.feature.feature.group 0.0.8.201111131640)
To: at.bestsolution.efxclipse.runtime.di [0.0.8.201111131640]
回答by Sergey Grinev
There are two options:
有两种选择:
1) EDIT:Since 7u35 (or smth near it) JavaFX was included into base JDK classpath so you can use JavaFX classes right away.
1)编辑:由于 7u35(或其附近的 smth)JavaFX 包含在基本 JDK 类路径中,因此您可以立即使用 JavaFX 类。
Just set up your projects to use fx libs:
只需设置您的项目以使用 fx 库:
JavaFX 2.0 API is pure Java. So you can create a new Java project and add sdk-path/rt/lib/jfxrt.jar
to libraries to use JavaFX in that project.
JavaFX 2.0 API 是纯 Java。因此,您可以创建一个新的 Java 项目并添加sdk-path/rt/lib/jfxrt.jar
到库中以在该项目中使用 JavaFX。
For cobundled builds in JDK7 path would be next jdk-path/jre/lib/jfxrt.jar
对于 JDK7 路径中的联合构建将是下一个 jdk-path/jre/lib/jfxrt.jar
2) Use e(fx)clipse plugin: http://www.eclipse.org/efxclipse/index.html
2) 使用 e(fx)clipse 插件:http: //www.eclipse.org/efxclipse/index.html
回答by Valentin Vrinceanu
You can use e(fx)clipse! You can find it here: http://www.eclipse.org/efxclipse/index.html
您可以使用 e(fx)clipse!你可以在这里找到它:http: //www.eclipse.org/efxclipse/index.html
After download you must to configure the IDE with your JavaFX SDK(must be installed).
下载后,您必须使用 JavaFX SDK(必须安装)配置 IDE。
All you need to do is to open Window > Preferences > JavaFX and configure the location of your JavaFX-SDK.
您需要做的就是打开 Window > Preferences > JavaFX 并配置 JavaFX-SDK 的位置。
You ussualy have it in Program Files > Oracle.
您通常在 Program Files > Oracle 中拥有它。
Hope this will help you!
希望能帮到你!
回答by loloof64
Based on Sergey Grinev solution, I noticed that we can define this once for all java projects.
基于 Sergey Grinev 解决方案,我注意到我们可以为所有 Java 项目定义一次。
- Go to Preferences -> Java build path
- Select the jvm which is supposed to support javaFx (but whose feature is not yet recognized in Eclipse) and Edit it
- Add the sdk-path/rt/lib/jfxrt.jar to it
- 转到首选项 -> Java 构建路径
- 选择应该支持 javaFx 的 jvm(但其功能在 Eclipse 中尚未识别)并编辑它
- 将 sdk-path/rt/lib/jfxrt.jar 添加到其中
This way, all your java projects based on this JVM version can support JavaFx and even your older projects (Select each project build path and eventually replace the old jvm with the jvm that you've just edited)
这样,您所有基于此 JVM 版本的 java 项目都可以支持 JavaFx 甚至您的旧项目(选择每个项目构建路径并最终将旧 jvm 替换为您刚刚编辑的 jvm)
回答by Georg
To access JavaFx in Java8 with Eclipse Luna (4.4):
使用 Eclipse Luna (4.4) 在 Java8 中访问 JavaFx:
Go to Build Path/ JRE/ Access rules/ Edit/ Add/ Accessible: javafx/**
转到构建路径/JRE/访问规则/编辑/添加/可访问:javafx/**
This seems better than editing the classpath file manually or adding the JAR (again) to the build path.
这似乎比手动编辑类路径文件或将 JAR(再次)添加到构建路径更好。
回答by mancini0
If you don't mind working with java 8, you won't have to jump through any hoola hoops. Just set that as your default jre and javafx imports work out of the box.
如果您不介意使用 java 8,您将不必跳过任何圈套。只需将其设置为您的默认 jre 和 javafx 导入即可使用。
回答by Paul Webster
As an aside, it says it won't install the FX plugin because you are missing org.eclipse.e4.core.contexts
bundle. Were you trying to install it into Eclipse Indigo, or 3.8? Or did you follow the instructions on the website and download eclipse 4.2 before you started?
顺便说一句,它说它不会安装FX插件,因为您缺少org.eclipse.e4.core.contexts
捆绑包。您是否尝试将其安装到 Eclipse Indigo 或 3.8 中?或者你在开始之前是否按照网站上的说明下载了eclipse 4.2?
回答by Ishwor
To install the e(fx)clipse tooling into your already existing Eclipse you have to add an Update site.
要将 e(fx)clipse 工具安装到您已经存在的 Eclipse 中,您必须添加一个更新站点。
There's no released yet available so you need to add the nightly update-site http://download.eclipse.org/efxclipse/updates-nightly/site
尚未发布,因此您需要添加每晚更新站点http://download.eclipse.org/efxclipse/updates-nightly/site
回答by Tiago Freitas Leal
I installed Eclipse Neon.1 (4.6.1) Then Help => Eclipse Marketplace On find specify "javaFX" and install "e(fx)clise 2.4.0"
我安装了 Eclipse Neon.1 (4.6.1) 然后 Help => Eclipse Marketplace On find 指定“javaFX”并安装“e(fx)clise 2.4.0”