【问题标题】:IntelliJ no longer recognises JavaFX componentsIntelliJ 不再识别 JavaFX 组件
【发布时间】:2021-07-03 13:46:06
【问题描述】:

我设法弄坏了我的旧 MacBook,换了一台新的。重新安装 IntelliJ 并从 Git 检索 Kotlin TornafoFX 项目后,IDE 不再识别任何 JavaFX 组件。我在 POM 中添加了 JavaFX,现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<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>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>tornadofx-maven-project</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <properties>
        <kotlin.version>1.2.60</kotlin.version>
        <tornadofx.version>1.7.17</tornadofx.version>
        <javafx.version>13</javafx.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>no.tornado</groupId>
            <artifactId>tornadofx</artifactId>
            <version>${tornadofx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                        <jvmTarget>1.8</jvmTarget>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我也收到 IDE 报告的类似错误:

java.lang.NoClassDefFoundError: javafx/scene/paint/Color

这在我的旧机器上没有发生,而且在 POM 中甚至不需要 JavaFX。谁能帮帮我?

【问题讨论】:

  • 对我来说,intellij 的缓存经常被弄乱。来自终端的“mvn clean package”是否成功运行?尝试修复 intelliJ 缓存的两件事: - 右键单击​​您的项目,转到 Maven-> 重新加载项目 如果这不起作用,请尝试: - 文件 -> 使缓存无效/重新启动 一旦 intelliJ 重新启动,索引将被重建并这将在正确的位置获得依赖项。
  • @Niro,不幸的是这并没有解决它:(我也尝试过不同的 Kotlin 版本和 JDK 版本
  • 你用什么JDK?

标签: java kotlin intellij-idea javafx tornadofx


【解决方案1】:

结果我不得不恢复到 JDK1.8。不会问为什么...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    相关资源
    最近更新 更多