【问题标题】:Issues with java dependencies (Intellij/Maven)java依赖问题(Intellij/Maven)
【发布时间】:2015-10-27 21:20:54
【问题描述】:

我无法在 Intellij 的 java 项目中导入一组库。我正在使用 maven 来解决依赖关系; pom文件中的依赖如下:

pom.xml

...
<dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.0.21.Final</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.3.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.fiware.kiara</groupId>
            <artifactId>kiaraparser</artifactId>
            <version>0.2.0</version>
        </dependency>
</dependencies>
...

它们已成功包含在类路径中。但是,当我尝试在项目中使用它们时:

import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

抛出以下错误:

Error:(20, 41) java: package com.google.common.util.concurrent does not exist
Error:(21, 32) java: package io.netty.util.concurrent does not exist
Error:(22, 32) java: package io.netty.util.concurrent does not exist
Error:(34, 81) java: cannot find symbol
  symbol: class ListenableFuture
Error:(34, 59) java: cannot find symbol
  symbol: class Future

这些库存在于类路径中:

为什么它们在构建时不包含在项目中?

编辑#1:

在 Intellij 中导入项目的具体步骤如下所示:

在执行“文件 -> 使缓存/重新启动无效”和“重新导入所有 Maven 项目”之后,错误仍然存​​在。这两个操作后创建的日志文件内容显示为here

为什么没有加载依赖项?

编辑#2:

按照here 提到的建议,我现在得到一个类型为“模块不能包含源根目录。根目录已经属于模块”的错误

【问题讨论】:

  • 有时,Intellij 在导入 maven 依赖项时会出现问题(您可以通过查看 idea.log 进行检查),而我可以通过右键单击来解决问题项目并选择 Maven -> Reimport。有时我还需要执行 File -> Invalidate Cache / Restart。
  • 我尝试过无效缓存/重启并重新导入所有依赖项,但没有成功

标签: java android windows maven intellij-idea


【解决方案1】:

我已经通过打开项目目录来修复它;在 Intellij 的菜单中选择第三个选项:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多