简体   繁体   English

将所有Maven库批量添加到IntelliJ中的类路径

[英]Bulk add all Maven libraries to classpath in IntelliJ

I've recently cloned a project and run mvn clean install which has installed all the dependencies listed in my the pom.xml . 我最近克隆了一个项目,然后运行mvn clean install ,它已经安装了pom.xml列出的所有依赖项。 Whenever I open a class I see a lot of import statements that are trying to import a third party class are highlighted with the error cannot resolve symbol Foo . 每当我打开一个类时,我都会看到很多试图导入第三方类的导入语句都突出显示,并带有错误cannot resolve symbol Foo的错误。 When I Alt+Enter there is an option to add the library to the classpath which completely resolves the issue - for this library: 当我Alt + Enter时,有一个选项可以将库添加到类路径中,这可以完全解决问题-对于该库:

在此处输入图片说明

This would be fine but I have many libraries I need to do this for. 很好,但是我需要为此做很多库。 Is there a way I can do this in bulk? 有没有办法我可以批量执行此操作?

EDIT 编辑

It's been brought to my attention that I shouldn't have to do this after a mvn clean install if that command completes successfully. 引起我注意的是,如果该命令成功完成,则在执行mvn clean install后不必执行此操作。 As such this is the error I'm getting as the very last part of my logs: 因此,这是我在日志的最后一部分中遇到的错误:

Exception in thread "Thread-9" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils
        at org.apache.tomcat.maven.plugin.tomcat7.run.RunMojo$1.run(RunMojo.java:140)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        ... 1 more

IntelliJ has good Maven support . IntelliJ具有良好的Maven支持 You should not have to add these dependencies into IntelliJ project manually if you imported the project from Maven pom.xml . 如果从Maven pom.xml导入了项目,则不必手动将这些依赖项添加到IntelliJ项目中。 Make sure you are selecting Import project from external model option when importing. Import project from external model请确保选择“ Import project from external model选项。

Does your project build with mvn clean install ? 您的项目是否使用mvn clean install构建? If not, make sure that it does before changing anything in IntelliJ. 如果没有,请确保在更改IntelliJ中的内容之前执行此操作。 Afterwards re-import the project into IntelliJ and double check File | Settings | Build, Execution, Deployment | Build Tools | Maven 然后将项目重新导入IntelliJ并仔细检查File | Settings | Build, Execution, Deployment | Build Tools | Maven File | Settings | Build, Execution, Deployment | Build Tools | Maven File | Settings | Build, Execution, Deployment | Build Tools | Maven configuration eg ensure that you are using the same Maven installation in command line and IntelliJ. File | Settings | Build, Execution, Deployment | Build Tools | Maven配置,例如,确保在命令行和IntelliJ中使用相同的Maven安装。

Perhaps you have something extra in your settings.xml configuration that makes it work in the command line but fails in IntelliJ when it runs with embedded Maven? 也许您的settings.xml配置中包含一些其他功能,使其可以在命令行中运行,但是在与嵌入式Maven一起运行时在IntelliJ中失败了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM