macos Maven 主页 (M2_HOME) 没有被 IntelliJ IDEA 接收
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7053666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven home (M2_HOME) not being picked up by IntelliJ IDEA
提问by Travis Nelson
I am trying to do a simple maven build with IntelliJ IDEA 10.5.1 on OS X Lion and am getting the following error:
我正在尝试在 OS X Lion 上使用 IntelliJ IDEA 10.5.1 进行简单的 maven 构建,但出现以下错误:
Error running my-app [package]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.
运行 my-app [package] 时出错:找不到有效的 Maven 安装。在配置对话框中设置主目录或在系统上设置 M2_HOME 环境变量。
I have set M2_HOME to the following, but I am still having issues. And yes, I did restart IntelliJ.
我已将 M2_HOME 设置为以下值,但仍有问题。是的,我确实重新启动了 IntelliJ。
$ echo $M2_HOME
/usr/share/maven
I then manually entered the path to maven in IntelliJ's Maven Settings for the project. This is not something that I want to do for every project, so is there something I am missing with how to get IntelliJ know where my maven home is?
然后我在项目的 IntelliJ 的 Maven 设置中手动输入了 Maven 的路径。这不是我想为每个项目做的事情,所以我是否缺少如何让 IntelliJ 知道我的 Maven 家在哪里的东西?
采纳答案by Amir Raminfar
Mac OS apps cannot read bash environment variables. Look at this question Setting environment variables in OS X?to expose M2_HOME
to all applications including IntelliJ. You do need to restart after doing this.
Mac OS 应用程序无法读取 bash 环境变量。看看这个问题在 OS X 中设置环境变量?向M2_HOME
包括 IntelliJ 在内的所有应用程序公开。执行此操作后,您确实需要重新启动。
回答by flutesa
type in Terminal:
输入终端:
$ mvn --version
then get following result:
然后得到以下结果:
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 16:51:28+0300)
Maven home: /opt/local/share/java/maven3
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: ru_RU, platform encoding: MacCyrillic
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
here in second line we have:
在第二行,我们有:
Maven home: /opt/local/share/java/maven3
type this path into field on configuration dialog. That's all to fix!
将此路径输入到配置对话框的字段中。这就是要解决的全部问题!
回答by MikeV
Another option is to add the M2_HOME variable at: IntelliJ IDEA=>Preferences=>IDE Settings=>Path Variables
另一种选择是在以下位置添加 M2_HOME 变量: IntelliJ IDEA=>Preferences=>IDE Settings=>Path Variables
After a restart of IntelliJ, IntelliJ IDEA=>Preferences=>Project Settings=>Maven=>Maven home directory
should be set to your M2_HOME variable.
重新启动 IntelliJ 后,IntelliJ IDEA=>Preferences=>Project Settings=>Maven=>Maven home directory
应将其设置为 M2_HOME 变量。
回答by Nimrod007
Got to this answer ? probably the answers above are to long ...
得到这个答案了吗?可能上面的答案太长了......
just type in :
只需输入:
echo "setenv M2_HOME $M2_HOME" | sudo tee -a /etc/launchd.conf
and restart your mac (thats it!)
并重新启动您的 Mac(就是这样!)
restarting is annoying ? just use the command :
重启很烦?只需使用命令:
grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
and restart IntelliJ IDEA
并重新启动 IntelliJ IDEA
回答by user5202836
If M2_HOME
is configured to point to the Maven home directory then:
如果M2_HOME
配置为指向 Maven 主目录,则:
- Go to
File -> Settings
- Search for
Maven
- Select
Runner
Insert in the field
VM Options
the following string:Dmaven.multiModuleProjectDirectory=$M2_HOME
- 去
File -> Settings
- 搜索
Maven
- 选择
Runner
在字段中插入
VM Options
以下字符串:Dmaven.multiModuleProjectDirectory=$M2_HOME
Click Apply
and OK
单击Apply
并OK
回答by Ali
In case you don't want to use the M2_HOME and want to direct the IntelliJ to the maven installation you can simply set it by:
如果您不想使用 M2_HOME 并希望将 IntelliJ 定向到 maven 安装,您可以简单地通过以下方式设置它:
- goto File => Setting => Maven => Maven home directory
- point to your maven build directory e.g. /usr/local/maven/apache-maven-3.0.4
- 转到文件 => 设置 => Maven => Maven 主目录
- 指向您的 maven 构建目录,例如 /usr/local/maven/apache-maven-3.0.4
A better way is to have a symlink e.g. 'latest' for the latest version and point your IntelliJ to use that for consistency, given latest points to the latest version of maven installed on your box.
更好的方法是有一个符号链接,例如最新版本的“最新”,并指出你的 IntelliJ 使用它来保持一致性,给出最新点到你的盒子上安装的最新版本的 maven。