java - Maven 在 IntelliJ 中找不到依赖项

标签 java maven javafx dependencies maven-plugin

我是 Maven 的新手,不太确定它的用途,但我认为它用于导入外部库,以便在编码时可以使用它们。我已经导入了依赖项并且没有错误,如下所示:

enter image description here

但是当键入导入时,它全部显示为红色,就好像没有找到一样。它没有找到任何东西。

enter image description here

如果我将整个导入行粘贴到其中,它会自动删除。

这不是 Maven 应该做的,还是在它起作用之前还有其他事情要做?我还将其设置为自动导入 Maven 项目

编辑:为清楚起见,它当然在我的 pom.xml 文件中,否则它不会出现在上面屏幕截图中的外部库中:

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>uk.co.caprica</groupId>
        <artifactId>vlcj</artifactId>
        <version>4.5.0</version>
    </dependency>
    <dependency>
        <groupId>uk.co.caprica</groupId>
        <artifactId>vlcj-javafx</artifactId>
        <version>1.0.2</version>
    </dependency>
</dependencies>

其他编辑:一些屏幕截图显示直接输入类并没有更好的效果。 Intellij 只是没有找到任何东西:

enter image description here enter image description here

最佳答案

似乎这个特定的依赖项是根据 Java Platform Module System 模块化的.因此,我们需要 module-info.java 文件中的 requires

module com.sample {
    requires javafx.controls;
    exports com.sample;
    requires transitive javafx.graphics;
    requires uk.co.caprica.vlcj;
    requires uk.co.caprica.vlcj.javafx;
}

在此之后,依赖关系突然可见并在代码中完全可用。

关于java - Maven 在 IntelliJ 中找不到依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65092978/

相关文章:

java - Maven:从子模块中排除资源

maven - JavaFX maven 程序集警告 : "Cannot include project artifact ... it doesn' t have an associated file or directory"

css - 无法更改验证器的颜色 (RequiredFieldValidator) JavaFX (JFoenix)

java - jTable更新按钮并添加新的

java - 寻找保存日期时间常量的标准 Java 辅助类或接口(interface)

java - 将 While 循环与 g.drawPolygon 代码结合使用

java - 白屏和崩溃-Android Studio

java - 带有 Eclipse 错误 "Path must include project and resource name"的 Maven

linux - 无法通过 http ://localhost:9000 with Sonarqube-4. 5.1 访问 SonarQube 服务器

javafx-2 - JavaFX 中的内部框架