简体   繁体   English

安装Java JDK 7之后对于Mac OS X - mvn -version仍然显示java版本1.6.0_31

[英]After Installing Java JDK 7 For Mac OS X - mvn -version still shows java version 1.6.0_31

Oracle released Java JDK 7 on April 26 for Mac OS X. I followed the install instructions and when I do java -version in a terminal window I get: Oracle于4月26日发布了适用于Mac OS X的Java JDK 7.我按照安装说明操作,当我在终端窗口中执行java -version时,我得到:

java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

However when I do mvn -version in the terminal window I get: 但是,当我在终端窗口中进行mvn -version ,我得到:

Apache Maven 3.0.2 (r1056850; 2011-01-08 18:58:10-0600)
Java version: 1.6.0_31, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.3", arch: "x86_64", family: "mac"

How can I get Maven to use the Java JDK 1.7.0_04? 如何让Maven使用Java JDK 1.7.0_04?

Thanks for the help. 谢谢您的帮助。

Finally found the answer here: 终于找到了答案:

http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7 http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7

You should use JAVA_HOME=$(/usr/libexec/java_home) instead on a Mac and then set the current jdk via "Java Preferences.app". 您应该在Mac上使用JAVA_HOME=$(/usr/libexec/java_home) ,然后通过“Java Preferences.app”设置当前的jdk。

Set JAVA_HOME in ~/.profile 在〜/ .profile中设置JAVA_HOME

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

To find the path from Java Preferences, try /usr/libexec/java_home -X 要从Java Preferences中查找路径,请尝试/usr/libexec/java_home -X

My Java7 entry looks like this: 我的Java7条目如下所示:

<dict>
    <key>JVMArch</key>
    <string>x86_64</string>
    <key>JVMBundleID</key>
    <string>com.oracle.java.7u04.jdk</string>
    <key>JVMEnabled</key>
    <true/>
    <key>JVMHomePath</key>
    <string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
    <key>JVMIsBuiltIn</key>
    <false/>
    <key>JVMName</key>
    <string>Java SE 7</string>
    <key>JVMPlatformVersion</key>
    <string>1.7</string>
    <key>JVMVendor</key>
    <string>Oracle Corporation</string>
    <key>JVMVersion</key>
    <string>1.7.0_04</string>
</dict>

You need to change the JAVA_HOME environment variable to the new JDK 1.7 location. 您需要将JAVA_HOME环境变量更改为新的JDK 1.7位置。

Look at this question for possible locations where JAVA_HOME might be defined. 请查看此问题,了解可能定义JAVA_HOME的位置。 In a terminal, type which java to find the path of your Java installation, and then update JAVA_HOME to point to that path (but exclude the trailing bin folder). 在终端中,键入which java来查找Java安装的路径,然后更新JAVA_HOME以指向该路径(但排除尾随bin文件夹)。

In case anyone is installing Maven on a 64-bit Mac running Mac OSX 'Mavericks' save yourself some time and some hair pulling trying to get Maven installed. 如果有人在64位Mac上安装Maven,运行Mac OSX'Mavericks'可以节省一些时间,并试图安装Maven。 I was trying to follow this (which failed because the location of the java_home has changed on Mavericks: 我试图遵循这个(失败,因为java_home的位置在Mavericks上发生了变化:

http://maven.apache.org/download.cgi http://maven.apache.org/download.cgi

I was pulling my hair out until I found this website, which recommends you Install homebrew and follow the instructions on this page: http://techspunky.blogspot.in/2013/10/how-to-install-maven-on-mac-osx-109.html 我把头发拉出来,直到找到这个网站,建议您安装自制软件并按照此页面上的说明操作: http//techspunky.blogspot.in/2013/10/how-to-install-maven-on-mac -osx-109.html

once complete don't panic when $ maven -version doesn't work, instead use $mvn --version as maven.apache.org/download.cgi recommended. 一旦完成,当$ maven -version不起作用时不要惊慌,而是使用$ mvn --version作为maven.apache.org/download.cgi推荐。

It worked, but then I noticed the Java SDK Maven was using was Java version: 1.6.0_65, which is not the latest SDK I installed on the system. 它工作,但后来我注意到Java SDK Maven使用的是Java版本:1.6.0_65,这不是我在系统上安装的最新SDK。

Once I set the JAVA_HOME= /usr/libexec/java_home 一旦我设置了JAVA_HOME = /usr/libexec/java_home

It was using the correct SDK: Maven home: /usr/local/Cellar/maven/3.1.1/libexec Java version: 1.7.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac" 它使用了正确的SDK:Maven home:/usr/local/Cellar/maven/3.1.1/libexec Java version:1.7.0_45,vendor:Oracle Corporation Java home:/Library/Java/JavaVirtualMachines/jdk1.7.0_45。 jdk / Contents / Home / jre默认语言环境:en_US,平台编码:UTF-8操作系统名称:“mac os x”,版本:“10.9”,arch:“x86_64”,系列:“mac”

Success! 成功! but wait... next time I opened the terminal and ran mvn -v it went back to java version 1.6. 但是等等......下次我打开终端并运行mvn -v它又回到了java 1.6版本。 WTH! WTH!

its some sort of supposed bug from what I read use: echo JAVA_HOME= /usr/libexec/java_home -v 1.7 | 它从我读到的东西中得到某种假设的错误:echo JAVA_HOME = /usr/libexec/java_home -v 1.7 | sudo tee -a /etc/mavenrc sudo tee -a / etc / mavenrc

and now: 现在:

Maven home: /usr/local/Cellar/maven/3.1.1/libexec Java version: 1.7.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac" Maven主页:/usr/local/Cellar/maven/3.1.1/libexec Java版本:1.7.0_45,供应商:Oracle Corporation Java home:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre默认语言环境:en_US,平台编码:UTF-8操作系统名称:“mac os x”,版本:“10.9”,arch:“x86_64”,系列:“mac”

The reason Maven is still using Java 6 is that the /usr/bin/mvn script that launches it does not use the correct OS/X method for resolving the current Java version as specified in Java Preferences. Maven仍在使用Java 6的原因是启动它的/ usr / bin / mvn脚本没有使用正确的OS / X方法来解析Java Preferences中指定的当前Java版本。 See this Maven issue for details: 有关详细信息,请参阅此Maven问题:

http://jira.codehaus.org/browse/MNG-4226 http://jira.codehaus.org/browse/MNG-4226

Voting it up might get it fixed; 投票可能会得到修复; in the meantime, if you alter the /usr/bin/mvn script as shown in the comments & patch on that issue you will get the desired result. 与此同时,如果您更改/ usr / bin / mvn脚本,如该问题的注释和补丁中所示,您将获得所需的结果。

Ok on my machine. 我的机器好的。 Yes, the Oracle installer didn't exactly do its job, and it confused me to no end after 1.6 was still running. 是的,Oracle安装程序并没有完全正常工作,并且在1.6仍在运行之后让我感到困惑。

java run time was updated 

java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

but the SDK HOME is actually a sim link still pointing to 1.6 但SDK HOME实际上是一个仍然指向1.6的SIM链接

/Library/Java/Home in finder GetInfo points to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home /Library/Java/Home in finder GetInfo指向/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

in Terminal 在终端

./Home -> /System/Library/Frameworks/JavaVM.framework/Home

Go figure. 去搞清楚。

I found 1.7 here and I'm using that to build with: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home 我在这里找到1.7并且我正在使用它来构建: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home

I think the problem lies partly with the java launch mechanism. 我认为问题部分在于java启动机制。 I have been able to get Eclipse to run my code under Java7, but I think eclipse itself is still running under Java6. 我已经能够让Eclipse在Java7下运行我的代码,但我认为eclipse本身仍在Java6下运行。 Also, I have a java program that was last compiled a year ago, and built using jarbundler-2.1.0.jar (with option jvmversion="1.6+"). 另外,我有一个java程序,它是在一年前最后编译的,并使用jarbundler-2.1.0.jar(带有选项jvmversion =“1.6+”)构建。 When I double click the .app file it runs Java6, but when I double click the .jar file inside the .app it runs Java7. 当我双击.app文件时,它运行Java6,但是当我双击.app内的.jar文件时,它运行Java7。

Also, I do not use JAVA_HOME, but I still get the correct java version "1.7.0_04" shown in the question. 另外,我不使用JAVA_HOME,但我仍然得到问题中显示的正确的java版本“1.7.0_04”。 JAVA_HOME seems to be a red herring. JAVA_HOME似乎是一只红鲱鱼。 Maybe Maven needs it, but Eclipse doesn't seem to use it, and neither does launching jar files. 也许Maven需要它,但是Eclipse似乎没有使用它,也没有启动jar文件。

And after setting Java7 in the Java Preferences tool, it does not seem to affect launching .app java files. 在Java Preferences工具中设置Java7之后,它似乎不会影响启动.app java文件。 However it does make 'java -version' from the terminal work nicely. 但是它确实使终端的'java -version'工作得很好。 I tried unchecking everything but the Java7 option, and then Eclipse wouldn't run at all. 我尝试取消选中除Java7选项之外的所有内容,然后Eclipse根本不会运行。

If your JAVA_HOME is located at the local user's bash, mvn will pick the system's current java version no matter what JAVA_HOME you've set. 如果你的JAVA_HOME位于本地用户的bash,无论你设置了什么JAVA_HOME,mvn都会选择系统的当前java版本。

Hence first run the command ' which mvn ' and check which executable mvn you are using. 因此,首先运行命令' which mvn '并检查您正在使用哪个可执行文件mvn。 After that edit that mvn file and change the JAVA_HOME variable to your prefered java home. 之后编辑mvn文件并将JAVA_HOME变量更改为您喜欢的java主目录。

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

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