如何让 javafx 14 编译和运行? [英] how can I get javafx 14 to compile and run?

查看:31
本文介绍了如何让 javafx 14 编译和运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试学习 javafx,但我的笔记本电脑没有安装 javafx 的问题.我正在使用 Windows 10 机器,我目前安装了 jdk14,它运行良好,因为我最近一直在运行和编译 java 代码.我浏览了整个互联网,找不到任何指导我如何安装 javafx 的链接,我发现的所有链接都在安装它并使用 Eclipse、netbeans 和 intellij 等 IDE 运行它,但我正在使用 atom做我的编码.

我已经从

OpenJFX 作为依赖

我不知道 Atom 是否可以与依赖项管理器一起工作,但供您参考……

配置您的构建工具,例如 MavenGradle 自动下载和捆绑 OpenJFX 作为依赖项.

对于 Maven,这里是当前的 POM 配置用于 javafx-controls,用于 Java 和 OpenJFX 的 14 版.您可能需要 JavaFX Maven 插件 Maven Mojo (javafx-maven-plugin) 以及.

以下是基于我当前 JavaFX 应用中真实 POM 的示例 POM.

<插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><配置><发布>14</发布></配置></插件><插件><groupId>org.openjfx</groupId><artifactId>javafx-maven-plugin</artifactId><version>0.0.4</version><配置><mainClass>work.basil.jartran.App</mainClass></配置></插件></插件></build></项目>

您可以使用 Maven OpenJFX 项目提供的原型创建基于 Maven 的项目.上面看到的 POM 将自动为您创建.您可能需要更新版本号.

I am currently trying to learn javafx but I'm having the problem of my laptop not having javafx install. I am using a windows 10 machine, I currently have jdk14 installed which is working fine as I've been recently running and compiling java code. I've looked all over the internet and cannot find any links that instruct me on how to install javafx, all the links I've found have been installing it and running it with an IDE like eclipse, netbeans and intellij but I am using atom to do my coding.

I have downloaded the latest version of javafx 14 from here and I assume that I will have to add the path variable to the environment variables in windows but I am not sure if doing so will get things to work so I'd thought I'd post here just to get so more knowledgeable help.

I know jdk 7 or jdk 8 has javafx built in but I would like to keep jkd 14 as I have programs already written using jdk 14.

解决方案

OpenJFX

First, know that Oracle has open-sourced an implementation of JavaFX as the OpenJFX project, a sub-project on the OpenJDK project.

Further development of JavaFX/OpenJFX is now led by the company Gluon. That development of OpenJFX is vigorous, with versions 11, 12, 13, 14, and now pre-release 15 arriving almost lock-step with releases of Java 11, 12, 13, 14, and 15.

Rather than manually downloading JavaFX, I recommend either of these approaches:

  • Obtain a JDK with OpenJFX bundled
  • Use a dependency manager to auto-download OpenJFX into your app

JavaFX bundled with JDK

Replace your Java implementation with one that bundles the open-source implementation of JavaFX known as OpenJFX.

You can find at least two such bundled JDKs:

  • LibericaFX from BellSoft is one such implementation of Java, based on the OpenJDK project.
  • ZuluFX from Azul Systems, announced here. Tip: On their download page, use the Java Package pop-up menu to choose either JDK FX or JRE FX. As of 2020-05, they have not yet released version 14 of their JavaFX bundle, but they have versions 8, 11, and 13 of their ZuluFX. I suggest checking back later for 14, or contact the company. ZuluFX is free-of-cost, with an invitation to talk if you are interested in buying support for JavaFX.

Here is a flowchart I made to help folks in selecting a vendor of a Java implementation. Notice the "OpenJFX bundled?" branch near the bottom.

OpenJFX as a dependency

I do not know if Atom can work with a dependency manager, but for your information…

Configure your build tool such as Maven or Gradle to automatically download and bundle OpenJFX as a dependency.

For Maven, here is the current POM configuration for javafx-controls, for version 14 of both Java and OpenJFX. And you will likely want JavaFX Maven Plugin Maven Mojo (javafx-maven-plugin) as well.

Below is an example POM based on a real POM in a current JavaFX app of mine.

<project xmlns = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>work.basil.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>14</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>work.basil.jartran.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

You can create your Maven-based project by using a Maven archetype provided by the OpenJFX project. The POM seen above will be automatically created for you. You may need to update the version numbers.

这篇关于如何让 javafx 14 编译和运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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