macos Maven, JAVA_HOME w/ OS X
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2013346/
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, JAVA_HOME w/ OS X
提问by ian
Trying to get Maven, Java, and OS X to play nice together - something I've done multiple times without issue on Linux and Windows machines. I assumed all I needed to do was download Maven, setup my environment variables and I'd be good. So here's a snippet from my .bash_profile...
试图让 Maven、Java 和 OS X 一起玩得很好 - 我在 Linux 和 Windows 机器上做过多次没有问题的事情。我假设我需要做的就是下载 Maven,设置我的环境变量,我会很好。所以这是我的 .bash_profile 中的一个片段...
export JAVA_HOME=/Library/Java/Home/
export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export PATH=$PATH:$M2_HOME/bin
The JAVA_HOME
setting is what Apple recommends be used on this Q&A page. Yet after launching a terminal and running mvn --version
, here's the output...
该JAVA_HOME
设置是 Apple 建议在此问答页面上使用的设置。然而在启动终端并运行之后mvn --version
,这是输出......
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.6.0_17
Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.6.2" arch: "x86_64" Family: "mac"
Any idea why the JAVA_HOME
I'm setting in my .bash_profile is being ignored by Maven? It's causing problems because things like rt.jar
aren't found in the JAVA_HOME
Maven is using. I can work around this by creating symbolic links and other hackery in the home Maven is using, but I'd rather have it work correctly since this will just blow up on me the next time Apple pushes a Java update. Thanks for any help...
知道为什么JAVA_HOME
.bash_profile 中的I 设置被 Maven 忽略了吗?它会导致问题,因为rt.jar
在JAVA_HOME
Maven 使用中找不到类似的东西。我可以通过在 Maven 正在使用的家庭中创建符号链接和其他hackery来解决这个问题,但我宁愿让它正常工作,因为下次Apple推送Java更新时这只会对我造成影响。谢谢你的帮助...
回答by Mahmoud Adam
The problem is that the symbolic link "CurrentJDK" inside the versions of JavaVm.framework points to the old jdk, so when i used the following commands to set the CurrentJDK to the latest one (1.7.0_45) it works
问题是 JavaVm.framework 版本中的符号链接“CurrentJDK”指向旧的 jdk,因此当我使用以下命令将 CurrentJDK 设置为最新的(1.7.0_45)时,它可以工作
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents CurrentJDK
reference: http://java.dzone.com/articles/installing-jdk-7-mac-os-x
参考:http: //java.dzone.com/articles/installing-jdk-7-mac-os-x
回答by miner49r
On Mac OS X, you should use /usr/libexec/java_home to determine the correct JAVA_HOME.
在 Mac OS X 上,您应该使用 /usr/libexec/java_home 来确定正确的 JAVA_HOME。
回答by hcayless
On my Mac, /Library/Java/Home is a symlink (actually the start of a chain of symlinks) that ultimately points to /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home. So I don't think maven is ignoring anything. It's just giving you the actual location.
在我的 Mac 上,/Library/Java/Home 是一个符号链接(实际上是符号链接链的开始),最终指向 /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home。所以我不认为 maven 会忽略任何事情。它只是为您提供实际位置。
回答by user244816
I have the same setup and all works fine. UNSET the "JAVA_HOME" environment variable in your shell script. The Mac install takes care of that. You are setting it wrong anyways.
我有相同的设置,一切正常。在您的 shell 脚本中取消设置“JAVA_HOME”环境变量。Mac 安装会处理这个问题。反正你设置错了。
Unset it, source your file or startup shell and try again.
取消设置,获取文件或启动 shell,然后重试。
回答by ennuikiller
well the first thing I would check is whether mvn is a script. If it is you can see how it's sourcing the environment. If it isn't I would look for any config files typically named .mvnrc, or something in /etc. Of course it wouldn't hurt to RTFM!
好吧,我要检查的第一件事是 mvn 是否是脚本。如果是,您可以看到它是如何采购环境的。如果不是,我会寻找任何通常名为 .mvnrc 的配置文件,或 /etc 中的内容。当然不会对RTFM造成伤害!