我刚刚从subversion导入了一个项目到IntelliJ IDEA 11——这是一个maven项目。但是我在maven库依赖关系中有一个问题,所以我不能自动包括所有maven依赖关系- IDEA只在我打开该类时显示依赖错误/这就是我在这里得到的:

所以我想要自动添加所有依赖项-这是可能的还是我必须遍历所有类文件来识别和添加maven依赖项?!

更新:在做了一些修改之后,我发现了如何以某种方式解决我的问题。我就是这么做的:

但我认为从逻辑上讲,它不会包括和检查新的依赖关系?!在intelliJ - auto export dependencies to classpath中是否有设置区域?


当前回答

我遇到了同样的问题,尝试了所有建议的方法,但都没有解决问题,我使用的是Intellij 13.1.3版

最后,在花了几个小时试图修复它之后,我决定尝试升级版本,并在14.1.4版本中打开项目,最终解决了这个问题。我认为这可能是前一个版本的bug。

我希望这能有所帮助!

其他回答

我能够通过从项目设置->模块列表中删除不必要的模块来解决这个问题。

当我从项目文件夹导入IntelliJ项目时(而不是通过打开pom.xml),这些额外的模块是由IntelliJ IDEA自动创建的。然后,在将项目声明为Maven项目之后,创建了适当的模块,现有模块与之冲突。在项目创建期间也可以排除这些模块。

From maven tab click + and choose pom.xml From maven tab click download sources and documentation On project structure(where you can view project files/directories) right click the project you're trying to build and choose Build Module Project Name. From tab Run- Edit Configurations with + add Application and fill the below fields: i. Main Class- Manually choose from Project tab select the main class ii. Use classpath of module - choose the application name iii. Shorten command line - classpath file Now simply run the app.

我能够通过在pom.xml文件中的构建标记后添加这行代码来修复我的问题,我从我的运行项目中进行比较,发现这是不同的,现在我都很好。

<repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

在我的例子中,MAVEN使用的JAVA路径没有设置为机器上配置的JAVA_HOME。因此,它甚至没有尝试下载依赖项。 我遵循的步骤解决了这个问题,

检查JAVA路径,设置>>构建>>构建工具>>导入>>导入器的JDK。指向JAVA_HOME。 mvn clean install -U 使用上述命令强制下载依赖项。 重新导入Maven项目

这个问题的一个可能的模式是,你没有连接到Nexus,基本上你想在离线模式下构建项目。但是当您导入项目时,Idea会尝试自动下载Maven依赖项。和失败。您在设置中设置了脱机工作复选框,但为时已晚:在首次下载尝试中已经出现故障。这里列出的两个选项都不能解决这个问题。相反,我做了以下事情:

第一个创建空Java(不是Maven)项目 选中Maven设置中的离线工作选项 将我的项目作为Maven模块添加到这个新项目中

这样就成功了。