JavaFX 2.0 + NetBeans +梅文
我正在使用 NetBeans 7.0.1 创建 JavaFX 2.0 应用程序。当我以标准方式创建项目时,一切正常。不幸的是;)我需要 Maven 项目...
我在 Maven 存储库中没有找到 JavaFX 2.0,所以我的 pom.xml 现在看起来像这样:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>ui</artifactId>
<version>0.1</version>
<name>My Project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${env.JAVAFX_HOME}\lib\jfxrt.jar</systemPath>
</dependency>
</dependencies>
</project>
JAVAFX_HOME 系统变量已设置:
C:\Users\rach>echo %JAVAFX_HOME%
C:\Program Files\Oracle\JavaFX Runtime 2.0\
编译正常,但是当我在 NetBeans 下启动程序时,出现错误:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application at java.lang.ClassLoader.defineClass1(Native Method)
然而 jfxrt.jar 在类路径中:
C:\>echo %CLASSPATH%
C:\Program Files\Oracle\JavaFX Runtime 2.0\lib\jfxrt.jar
当我从命令行启动应用程序时,它工作正常。
当我在运行时在本地存储库中安装 jfxrt.jar 时,应用程序仍然无法启动,因为它找不到 C:\Program Files\Oracle\JavaFX Runtime 2.0\bin\mat.dll。 Pom.xml:
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
效果:
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Repositories\MavenRepo\javafx\jfxrt\bin\mat.dll at com.sun.javafx.tk.quantum.QuantumToolkit.startup(Unknown Source)
有什么想法吗?
I am creating JavaFX 2.0 application using NetBeans 7.0.1. When I create project in standard way everything works fine. Unfortunately ;) I need Maven project...
I didn't find JavaFX 2.0 in Maven repository, so my pom.xml right now looks like this:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>ui</artifactId>
<version>0.1</version>
<name>My Project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${env.JAVAFX_HOME}\lib\jfxrt.jar</systemPath>
</dependency>
</dependencies>
</project>
JAVAFX_HOME system variable is set:
C:\Users\rach>echo %JAVAFX_HOME%
C:\Program Files\Oracle\JavaFX Runtime 2.0\
Compilation goes okay, but when I start program under NetBeans I got error:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application at java.lang.ClassLoader.defineClass1(Native Method)
However jfxrt.jar is in classpath:
C:\>echo %CLASSPATH%
C:\Program Files\Oracle\JavaFX Runtime 2.0\lib\jfxrt.jar
When I start my application from command line it works fine.
When I install jfxrt.jar in local repository at runtime application still does not start because it cannot find C:\Program Files\Oracle\JavaFX Runtime 2.0\bin\mat.dll. Pom.xml:
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
<version>2.0</version>
<type>jar</type>
</dependency>
Effect:
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Repositories\MavenRepo\javafx\jfxrt\bin\mat.dll at com.sun.javafx.tk.quantum.QuantumToolkit.startup(Unknown Source)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢您的帮助。
对于那些使用 JavaFX 2.0 SDK 的人来说,这里是简单的步骤
在 shell 中转到 JavaFX 2.0 SDK\rt\lib(命令提示符)
执行 mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx -Dpackaging=jar -Dversion=2.0
从 JavaFX 2.0 SDK 复制 bin 文件夹\rt\ 目录到您的 .m2\repository\com\oracle\javafx 目录
4.
com.oracle ;
javafx ;
<版本>2.0
<范围>编译
Thank you for your help.
Those who are using JavaFX 2.0 SDK here are simple steps
Go to JavaFX 2.0 SDK\rt\lib in your shell (command prompt)
Execute mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx -Dpackaging=jar -Dversion=2.0
Copy bin folder from your JavaFX 2.0 SDK\rt\ directory to your .m2\repository\com\oracle\javafx directory
4.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
当前 Java 7 与捆绑的 Java FX 2.0 的最佳答案是:
并将其添加到 NetBeans 中使用的 Maven 配置文件的“运行项目”操作中:
您还可以将其与“调试项目”、“配置文件项目”一起使用、“通过 main() 运行文件”、“通过 main() 调试文件”和“通过 main() 配置文件”操作:)
The best answer for current Java 7, with bundled Java FX 2.0, is:
and add this to the "Run Project" Action of the used Maven profile in NetBeans:
You can also use this with the "Debug project", "Profile Project", "Run file via main()", "Debug file via main()", and "Profile file via main()" actions :)
目前,这似乎是一个有效的解决方案。
首先,安装 jfxrt.jar:
然后将 bin 文件夹从下载的 JavaFX 运行时复制到本地 Maven 存储库 (home/.m2/repository/com/oracle/javafx-运行时/)
不是很优雅,但它对我有用..
For now, this seems to be a solution that works..
First, install the jfxrt.jar:
Then copy the bin folder from your downloaded JavaFX runtime into your local Maven repo (home/.m2/repository/com/oracle/javafx-runtime/)
Not very elegant, but it works for me..