【发布时间】:2012-03-06 20:51:42
【问题描述】:
是否可以在 pom.xml 中将 JavaFX 2.0 引用为 Maven 中的依赖项,以便一切顺利进行?
我在this question 中看到可以在本地安装 jfxrt.jar,但理想情况下,我想要一种更简单的方法,可以在没有任何本地黑客的情况下正确解决和下载依赖项....
【问题讨论】:
是否可以在 pom.xml 中将 JavaFX 2.0 引用为 Maven 中的依赖项,以便一切顺利进行?
我在this question 中看到可以在本地安装 jfxrt.jar,但理想情况下,我想要一种更简单的方法,可以在没有任何本地黑客的情况下正确解决和下载依赖项....
【问题讨论】:
不,目前不存在这样的解决方案。我怀疑它永远不会,因为从 Java 1.7 update 2 开始,JavaFX 与 JVM 一起安装。计划从 Java 1.8(明年)开始在 JRE 中包含 JavaFX。从那时起,你就完全不需要依赖了。
但是,您现在已经可以将 Maven 与 JavaFX 一起使用,因为 Maven 可以调用 Ant 任务(antrun 插件),并且 JavaFX 发行版中提供了超级 Ant 任务。我写了一篇关于它的博客,但它是用法语写的:Creer un projet Maven pour JavaFX2。它会引导您完成整个过程。不过,如果您不懂法语,请在文章中发表评论,我会尽力帮助您或在the Oracle forum查看这里
【讨论】:
Sergey 的文章建议添加 javafx 作为系统依赖,不应该使用。相反,您可以在 POM 中包含以下内容以自动安装 javafx。
<profile>
<id>install-javafx</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-javafx</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
<configuration>
<file>${jfx-runtime}/lib/jfxrt.jar</file>
<groupId>javafx</groupId>
<artifactId>javafx</artifactId>
<version>${jfx-version}</version>
<packaging>jar</packaging>
<javadoc>${jfx-runtime}/../docs/api.zip</javadoc>
<!--<sources>no source available</sources>-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>install-javafx-bin</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${settings.localRepository}/javafx/javafx</outputDirectory>
<useBuildFilters>false</useBuildFilters>
<resources>
<resource>
<directory>${jfx-runtime}</directory>
<includes>
<include>bin/*.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
如果您想安装 api 文档,请将 docs/api 文件夹的内容压缩到 docs/api.zip。现在您只需运行 maven,激活配置文件并设置 jfx-runtime 和 jfx-version 属性。
【讨论】:
${jfx-runtime} 和${jfx-version}。只是在<properties/> 部分硬编码它们?
jfx-runtime 的可能值是多少? (不是硬编码路径)。
这是一个可能的解决方案。
在您的项目目录中创建一个lib 文件夹并将jfxrt.jar 放入该目录。
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jfxrt.jar</systemPath>
</dependency>
如果你想构建一个可执行的jar,你只需要包含javafx-maven-plugin。欲了解更多信息,请参阅:link-to-github
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>[put your application main class here]</mainClass>
</configuration>
</plugin>
【讨论】: