如何使用 netbeans 将 javafx 添加到 java 15.01 sdk

问题描述

这里是 Java 新手。我有一个使用 maven 的关于 netbeans 的 java 项目。我正在尝试将 javafx 添加到我的项目中。

我在 pom.xml 文件添加了以下内容

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>15</version>
            <type>pom</type>
        </dependency>

但是当我尝试在 netbeans 中构建我的项目时,我收到此错误(tsInfluence 是包含尝试调用 jfx 的主要方法的类):

Error: LinkageError occurred while loading main class com.ts.tsInfluence.tsInfluence
    java.lang.classFormatError: Invalid superclass index 0 in class file com/ts/tsInfluence/tsInfluence
Command execution Failed.

解决方法

转到项目属性 -> 库 -> 添加新的类路径(库) -> 给出名称等 -> 然后添加到 javafx 的 scr zip 的路径

编辑: 你没有看到这样的窗口吗?项目名称上的鼠标右键 enter image description here

编辑 2: 哦对了……在 Maven 中你需要遵循这个 http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

这里回答了一个类似的问题...你应该按照他们说的去做,只需替换你的文件路径

Question close to this

,

您的设置不起作用,因为“javafx”不是有效的工件 ID。您必须提供(可能不止一个)这样的依赖项。

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>15.0.1</version>
</dependency>

有关详细信息,请阅读文档:https://openjfx.io/openjfx-docs/#maven