简体   繁体   English

JavaFX 应用程序类不在 javafx.application 包中

[英]JavaFX Application class not in javafx.application package

I recently have updated Eclipse to version 2019-12 and my JDK to Java SE 13, and I learned afterwards that this JSE no longer includes JavaFX as a core library.我最近将 Eclipse 更新到了 2019-12 版本,将我的 JDK 更新到了 Java SE 13,后来我了解到这个 JSE 不再包含 JavaFX 作为核心库。 So, I looked up the Maven dependency entries for newer JavaFX libraries compatible with JSE 13 and picked version 11. I added them to my pom.xml file as such:因此,我查找了与 JSE 13 兼容的较新 JavaFX 库的 Maven 依赖项,并选择了版本 11。我将它们添加到我的pom.xml文件中,如下所示:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>...</modelVersion>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <url>https://github.com/.../url>
    <name>...</name>
    <description>...</description>

    <dependencies>
        ...
        ...
        <!-- JavaFX is no longer included in JDK --> 
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>11</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
       </dependency>
       <dependency>
           <groupId>org.openjfx</groupId>
           <artifactId>javafx-fxml</artifactId>
           <version>11</version>
       </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

However, now some javafx imports in my source files cannot be resolved.但是,现在我的源文件中的某些javafx导入无法解析。 For example:例如:

import javafx.application.Application; //Application class not found
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.paint.Color; //Color class not found

I've checked the javadocs for the javafx...Application and javafx...Color classes, and it appears they should be included among the class files within the graphics , controls , and fxml modules I linked as dependencies in the pom.xml file.我已经检查了javafx...Applicationjavafx...Color类的 javadoc,看起来它们应该包含在我作为依赖fxml pom.xmlgraphicscontrolsfxml模块中的类文件中文件。

Why are my imports not resolving?为什么我的导入无法解析?

Oh never mind.哦,没关系。 I was bumbling with this for a couple hours before I tried bumping up to JavaFX 13 in my Maven dependencies and now everything works.在我尝试在我的 Maven 依赖项中升级到 JavaFX 13 之前,我已经搞砸了几个小时,现在一切正常。

:/ :/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM