JavaFX 2 作为 Maven 依赖项

发布于 2025-01-05 08:49:49 字数 226 浏览 4 评论 0原文

是否可以在 pom.xml 中引用 JavaFX 2.0 作为 Maven 的依赖项,以便一切顺利进行?

我在这个问题中看到可以在本地安装jfxrt.jar,但是理想情况下,我想要一种更简单的方法,可以正确解决和下载依赖项,而无需任何本地黑客......

Is it possible to reference JavaFX 2.0 as a dependency in Maven in the pom.xml so that everything works smoothly?

I saw in this question that it is possible to install the jfxrt.jar locally, but ideally I'd like a simpler approach where the dependency can be properly resolved and downloaded without any local hacks....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以往的大感动 2025-01-12 08:49:49

这是一个可能的解决方案。

在项目目录中创建一个 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>

here is a possible solution.

Create a lib folder in your project directory and put the jfxrt.jar into that directory.

<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>javafx</artifactId>
  <version>2.2.3</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/lib/jfxrt.jar</systemPath>
</dependency>

And if you want to build an executable jar you only need to include the javafx-maven-plugin. For further information see: 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>
陈独秀 2025-01-12 08:49:49

不,目前还不存在这样的解决方案。我怀疑它会永远存在,因为从 Java 1.7 update 2 开始,JavaFX 与 JVM 一起安装。计划从 Java 1.8(明年)开始将 JavaFX 纳入 JRE。从那时起,你就不再需要依赖了。

不过,您现在已经可以将 Maven 与 JavaFX 一起使用,因为 Maven 可以调用 Ant 任务(antrun 插件),并且 JavaFX 发行版提供了超级 Ant 任务。我在博客上写过它,但它是法语的: Creer一个针对 JavaFX2 的 Maven 项目。它会引导您完成整个过程。不过,如果您不懂法语,请在文章中发表评论,我会尽力帮助您或查看这里 Oracle 论坛

No, such a solution doesn't exist for the moment. I doubt that it will ever, since as from Java 1.7 update 2, JavaFX is installed together with the JVM. Plans are to include JavaFX in the JRE as from Java 1.8 (next year). From then on, you wouldn't need a dependency at all.

However you can use Maven with JavaFX now already, because Maven can call Ant tasks (antrun plugin) and there are super Ant tasks available with the JavaFX distribution. I blogged about it, but it's in French: Creer un projet Maven pour JavaFX2. It walks you through the whole process. Nevertheless, if you don't understand French, leave a comment on the article and I will try to help you or look in here in the Oracle forum

流绪微梦 2025-01-12 08:49:49

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 属性。

The article of Sergey suggests to add javafx as a system dependency, which should not be used. Instead, you can include the following in your POM to install javafx automatically.

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

If you want to have api docs installed, zip the contents of of the docs/api folder to docs/api.zip. Now you just have to run maven, with the profile activated and the jfx-runtime and jfx-version properties set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文