在 IntelliJ IDEA 中导入 Maven 依赖项 [英] Import Maven dependencies in IntelliJ IDEA

查看:51
本文介绍了在 IntelliJ IDEA 中导入 Maven 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 IntelliJ IDEA 11 的小问题.我刚刚从 subversion 导入了一个项目 - 它是一个 maven 项目.但是我在 maven 库依赖项中遇到了问题,因此我无法自动包含所有 maven 依赖项 - IDEA 仅在我打开该类时才会显示依赖项错误/这就是我在这里得到的:

I have a small question about IntelliJ IDEA 11. I just imported a project from subversion - its a maven project. But I have a problem in maven library dependencies so that I can't include all maven dependencies automatically - IDEA shows dependency errors only when I open that class/ Thats what I get here:

所以我希望自动添加所有依赖项 - 这是可能的还是我必须通过所有类文件来识别和添加 maven 依赖项?!

So I want all dependencies to be added automatically - is that possible or do I have to go through all class files to identify and add maven dependencies?!

更新:做了一些修改后,我找到了如何以某种方式解决我的问题.这就是我所做的:

UPDATE: After doing some modifications I found how to resolve my problem in some way. Thats what I did:

但我认为从逻辑上讲它不会包含并提前检查新的依赖项?!...在intelliJ中是否有任何设置区域 - 自动将依赖项导出到类路径?!

but I think logically it will not include and check new dependencies ahead?!... Is there any settings area for this in intelliJ - auto export dependencies to classpath ?!

推荐答案

只要您的 POM 符合要求并且所有依赖项都可用,IntelliJ 应该会自动下载所有依赖项并将其添加到项目的类路径中.

IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.

在将 Maven 项目导入 IntelliJ 时,通常会出现一个信息框,询问您是否要为 Maven 项目配置自动导入.这意味着如果您对 POM 进行任何更改,这些更改将自动加载.

When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.

您可以通过 File > Settings > Maven > Importing 启用此类功能,其中有一个复选框显示自动导入 Maven 项目".

You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".

如果这没有帮助,那么我建议彻底清理并重新开始:

If that doesn't help, then I would suggest to make a full clean-up and start again:

  • 关闭您的项目窗口(和 IntelliJ)并删除所有 *.iml 文件和所有 .idea 文件夹(每个模块应该有一个)
  • 从命令行运行 mvn clean install
  • 将项目重新导入 IntelliJ 并注意它是否要求您启用自动导入
  • Close your project window (and IntelliJ) and remove all *.iml files and all .idea folders (there should be one per module)
  • Run mvn clean install from the command line
  • Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import

IntelliJ 2016 更新:

自动导入 Maven 项目设置已移至 IntelliJ 首选项中的构建、执行、部署 > 构建工具 > Maven > 导入.

The Import Maven Projects automatically setting has been moved to Build, Execution, Deployment > Build Tools > Maven > Importing in your IntelliJ preferences.

这篇关于在 IntelliJ IDEA 中导入 Maven 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆