平台:IntelliJ社区版10.0.3 SDK: jdk1.6.0_21 操作系统:Windows 7

所以我有一个奇怪的IntelliJ情况,让我完全难住了。我设置了一个Maven项目,并将log4j作为依赖项添加到pom.xml文件中。IDEA检查运行良好,我的单元测试全部编译并运行。

然后,我使用mvn install:install-file将hunnysoft的jmime库添加到我的本地maven存储库,如下所示。

mvn install:install-file -Dfile=jmime.jar -DgroupId=jmime \
-DartifactId=jmime -Dversion=3.1.1e -Dpackaging=jar

Maven将jar文件安装到我的本地存储库中。

然后进入IntelliJ的Settings => Maven => Repository Services并更新我的本地存储库(以便IntelliJ将重新索引存储库内容)。

最后,我将以下依赖项添加到pom.xml文件中(就在log4j依赖项的上面)。

<dependency>
    <groupId>jmime</groupId>
    <artifactId>jmime</artifactId>
    <version>3.1.1e</version>
</dependency>

我现在创建一个新类,如下所示:

package com.stackoverflow.question;

import org.apache.log4j.Logger;
import com.hunnysoft.jmime.ByteString;
import com.hunnysoft.jmime.Field;
import com.hunnysoft.jmime.FieldBody;

public class StackOverflowQuestion {
    public Field create(String name, String text) {
        Logger.getLogger(getClass()).debug("create entered");
        FieldBody body = new FieldBody();
        body.setText(new ByteString(text));
        Field field = new Field();
        field.setFieldName(name);
        field.setFieldBody(body);
        return field;
    }
}

现在说说奇怪的地方。IntelliJ的意图机制可以很好地拾取和识别maven pom文件中的Logger导入。然而,对于所有hunnysoft导入它报告:“不能解析符号'ByteString/Field/FieldBody'”,BUT Build => Compile 'StackOverflowQuestion.java'正确编译一切,我为这个类创建的单元测试运行良好(尽管意图标记调用create()作为一个问题区域太)。

IntelliJ忽略了意图子系统的jmime.jar文件。我很困惑,因为log4j依赖项工作得很好,所有东西都编译和运行得很好。F12(“Go To Declaration”)在Logger导入上有效,但在所有jmime导入上失效。

哦,还有一件事,如果我转到“项目”窗口的“包”视图,“com.hunnysoft”。出现了“jmime”包,我可以在“Libraries”下面看到我在上面的代码片段中导入的所有类。从pom.xml文件中删除上述依赖项将导致该包消失,编译中断。

似乎检查的类路径被破坏了,但在Settings => Intentions | Compiler区域中似乎没有对此进行设置(并不是说我期望有这样的设置,我相信IDEA应该已经知道基于pom文件和JDK的正确类路径)。

作为最后的实验,我创建了一个全新的标准J2SE应用程序项目(没有使用maven),并将jmime.jar文件直接添加到项目中作为其库之一。在这个新项目中,我遇到了与上面描述的完全相同的问题。

这是舱单。MF来自jmime jar文件。

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.4
Created-By: 10.0-b23 (Sun Microsystems Inc.)

Name: com/hunnysoft/jmime/
Sealed: true
Specification-Title: Hunny JMIME
Specification-Version: 3.1.1
Specification-Vendor: Hunny Software, Inc.
Implementation-Title: com.hunnysoft.jmime
Implementation-Version: 3.1.1E
Implementation-Vendor: Hunny Software, Inc.

我在这个罐子文件里没发现什么异常。

我最好的猜测是,这个问题可能是一个缺失的依赖问题。但是AFAIK jmime应该是自包含的(JarAnalyzer不会提供任何东西,但我不确定如果缺少一个依赖jar,它是否会提供任何东西)。

有人有什么想法吗?


当前回答

无效缓存为我工作,但运行后的应用程序有同样的错误。

所以我尝试了(Intellij):

1—菜单栏—重构|构建|运行|工具 -单击“构建”,然后“重建项目”

2百万

3 -右键单击项目> Maven >生成源代码和更新文件夹

希望这对你有用。

谢谢

其他回答

如果我所有的pom.xml文件都配置正确,并且IntelliJ中的Maven仍然存在问题,我将执行以下步骤

Read how to use maven in IntelliJ lately Make sure IntelliJ is configured to use Bundled Maven 3 Find and TERMINATE actual java process that is executing Maven 3 repos indexing for IntelliJ(Termination can be done while IntelliJ is running). In case any problems with indices or dependencies not available(thought repositories were configured in pom.xml). Forced Update for all repositories in "IntelliJ / Settings / Build Tools / Maven / Repositories / ". Takes most of the time, disk space and bandwidth! Took me 20+ minutes to update index for Maven central repo. Hit Re-import all Maven project once again from IntelliJ It is a good practice to do steps 1-4 to leave IntelliJ and its demon java processes running over night, if you have multiple repositories and a complex project, so you have everything in sync for the next day. You can in theory use all popular indexed repos out there and launch index update for all repos at the same time(I suppose IntelliJ creates a queue and runs updates one after another) then it can take hours to complete(you will need to increase heap space for that too).

注: 我花了几个小时来理解(步骤3)处理maven索引更新的IntelliJ的java恶魔进程做错了,我只需要让IntelliJ从头开始启动它。问题解决了,甚至没有重新启动IntelliJ本身。

修复已经发布了吗?出现的问题最初影响v11/12由于“编译器检修”早在2013年。2014年底在Jira就相关问题进行了讨论。 http://youtrack.jetbrains.com/issue/IDEA-98425

同样在Jira上,IDEA-98425被标记为固定但未验证(v12.0.3)。以下解决方案均无法帮助解决Windows 13.1.1版本的“无法解析符号”问题

a.删除。idealic13文件夹(然后,文件\失效缓存/重新启动)

b.从Maven项目窗口,

b.1 mvn - u idea:idea - >执行这个maven目标假设重新加载依赖项。这在以前的工作,但自从上次FRI,执行这个maven目标失败,因为它试图重新编译项目(当然它失败为“无法解析符号”,这就是我试图通过运行这个命令在第一个地方修复)mvn -version -显示maven版本引用3.2.5,它正在工作

b.2只需右键单击项目,并重新导入

b.3文件\无效缓存/重新启动

c.尝试启用和禁用此设置:File -> Settings -> Maven -> Importing -> "Use maven3 to import project"

d.设置\ Maven \ Multiproject构建失败策略=结束失败(而不是默认)

没有什么工作。Maven上的IntelliJ支持发生了什么。

https://youtrack.jetbrains.com/issue/IDEA-99302

来自JetBeans发布历史,https://www.jetbrains.com/company/history.jsp

IntelliJ v14 2014年11月

IntelliJ v13 12月2013

我假设v12修复(尽管未经验证)将被合并到后续版本中。有人在哪个IntelliJ版本上有类似的问题吗?请分享你的经验。IntelliJ maven支持似乎中断了。

其他的答案对我都不起作用。我的导入没有被解析,因为IntelliJ指向了错误的.m2文件。

IntelliJ版本:IntelliJ Idea 2018.1.5

.m2目录的位置指向了错误的路径。我所做的修复就是将IntelliJ重新指向正确的.m2目录并更新它。

首先,进入:文件->设置->构建,执行,部署->构建工具->Maven

我必须更改用户设置文件:和本地存储库:到我的.m2目录的正确位置。

在此之后,进入:文件->设置->构建,执行,部署->构建工具->Maven->存储库

并按“更新”按钮。

在使用Kotlin构建库时,我也遇到了类似的问题。我通过gradle包含了图书馆。 Intellij能够运行我的应用程序,但不能解析某些类及其方法。 然后我意识到我的Intellij中的Kotlin插件版本已经过时了,并且低于构建库的Kotlin版本。所以我更新了Kotlin插件 文件—>设置—>语言和框架—>Kotlin,它解决了这个问题。

我尝试了文件|无效缓存,删除。idea文件夹,缓存文件夹,重新导入项目。但是什么都不管用。

所以更新相应的插件会很有帮助。

下面的技巧帮我解决了这个问题:

右击代码编辑器 悬停在Maven上并展开 点击“重新导入”

我的想法版本是12.0.4