如何将JavaFX 2.0类添加到现有Maven项目中? [英] How can I add a JavaFX 2.0 class to an existing Maven project?

查看:243
本文介绍了如何将JavaFX 2.0类添加到现有Maven项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只在xy轴上显示图形的Maven项目。我想将该图更改为Javafx 2.0线图以显示相同的数据。我尝试使用FEST-javafx-maven插件,但我仍然无法编译代码;编译器找不到所有的javafx.xxx导入。

I have a Maven project that just displays a graph on the xy axis. I want to change that graph to a Javafx 2.0 linechart to display the same data. I tried using the FEST-javafx-maven plugin, but I still cannot compile the code; the compiler cannot find all of the javafx.xxx imports.

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

更新(2015年10月6日)

现代JavaFX版本(Oracle Java 8+附带)不需要任何其他使用JavaFX的类路径。 JavaFX运行时位于Java用于编译和执行的默认类路径上。这意味着没有其他依赖关系的普通maven pom.xml文件将构建JavaFX应用程序。

Modern JavaFX versions (shipped with Oracle Java 8+) do not require any additional class path to use JavaFX. The JavaFX runtime is on the default classpath Java uses for compilation and execution. This means that a plain maven pom.xml file, with no additional dependencies, will build a JavaFX application.

但是,如果您希望为您的应用程序使用其他打包功能,例如能够将其部署为自包含的应用程序,然后我建议使用(第三方) JavaFX Maven插件

However, if you wish to use additional packaging features for your application, such as the ability to deploy it as a self-contained application, then I advise using the (third party) JavaFX Maven plugin.

上一个答案

此答案中的以下信息现在已经过时且过时了。

The following information in this answer is now mostly old and outdated.

我找到的fest maven插件的链接( http://fest.easytesting。 org / javafx / maven / )是一个用于构建JavaFX 1.x脚本项目的工具,这是一个与JavaFX 2.0完全不同且不兼容的野兽 - 我不确定是否有更新版本的fest maven插件,支持JavaFX 2.0。

The link to the fest maven plugin I found (http://fest.easytesting.org/javafx/maven/) is to a tool for building JavaFX 1.x script projects, which is a completely different and incompatible beast to JavaFX 2.0 - I'm not sure if there is an updated version of the fest maven plugin which supports JavaFX 2.0.

目前没有官方支持来自Oracle的Maven,也没有公开托管的Maven存储库中的JavaFX 2.0版本。

There is currently no official support for Maven from Oracle, nor a version of JavaFX 2.0 in a publicly hosted Maven repository.

但是,我过去使用maven成功构建了JavaFX 2.0项目,方法是使用jfxrt.jar上的系统作用域依赖项,并(可选)从maven调用JavaFX ant任务。

However, I have successfully built JavaFX 2.0 projects using maven in the past by using a system scoped dependency on the jfxrt.jar and (optionally) invoking the JavaFX ant tasks from maven.

如果您通过JFXPanel将图形嵌入到现有的Swing应用程序中,那么您不需要使用JavaFX ant任务。从JavaFX运行时添加jfxrt.jar作为系统依赖项或手动将其安装到maven存储库中以使用非系统范围的依赖项。

If you are embedding your graph in an existing Swing application via a JFXPanel, then you don't need to use the JavaFX ant tasks. Add jfxrt.jar from the JavaFX runtime as a system dependency OR manually install it into your maven repository to use a non-system scoped dependency.

命令的示例手动安装所需的JavaFX 2.0运行时jar是:

An example of the command to manually install the required JavaFX 2.0 runtime jar is:

mvn install:install-file -Dfile="C:\Program Files\Oracle\JavaFX 2.1.0 SDK\rt\lib\jfxrt.jar" -DgroupId=com.oracle.javafx -DartifactId=javafx -Dversion=2.1 -Dpackaging=jar

运行上述命令后,将jfxrt.jar文件的依赖项添加到maven pom,项目编译应该解析所有JavaFX API参考:

After running the above command, add the dependency to the jfxrt.jar file to your maven pom and your project compilation should resolve all JavaFX API references:

<dependency>
  <groupId>com.oracle.javafx</groupId>
  <artifactId>javafx</artifactId>
  <version>2.1</version>
</dependency>

如果扩展JavaFX Application类,并且希望打包应用程序以通过webstart进行部署,浏览器嵌入或作为一个支持JavaFX安装的可点击jar,你应该调整你的pom.xml文件来执行相关的JavaFX 2.0 ant任务 - http://code.google.com/p/willow-browser/source/browse/pom.xml 演示了这样的改编。

If you extend the JavaFX Application class and you want your application packaged for deployment via webstart, browser embedding or as a JavaFX installation aware clickable jar, then you should adapt your pom.xml file to execute the relevant JavaFX 2.0 ant tasks - http://code.google.com/p/willow-browser/source/browse/pom.xml demonstrates such an adaption.

这些主题讨论JavaFX 2.0 maven支持并提供更多背景信息和样本:

These threads discuss JavaFX 2.0 maven support and provide further background info and samples:

  • https://forums.oracle.com/forums/thread.jspa?messageID=9970002
  • http://mail.openjdk.java.net/pipermail/openjfx-dev/2011-December/000076.html

这篇关于如何将JavaFX 2.0类添加到现有Maven项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆