更改 java 版本 (Mac)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19045829/
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
Change java version (Mac)
提问by Grains
I have 2 java versions on my computer:
我的电脑上有 2 个 Java 版本:
/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
The 1.6.0 is set to default. How can I make my java programs to run 1.7?
1.6.0 设置为默认值。如何让我的 Java 程序运行 1.7?
Tried to add:
尝试添加:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
to my .zshrcfile. But this seems to only change the path for my terminals java
command.
到我的.zshrc文件。但这似乎只会改变我的终端java
命令的路径。
Also tried to change the HOME symlink like this:
还尝试像这样更改 HOME 符号链接:
cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home
This had no effect at all.
这根本没有效果。
Also tried java changer software: http://www.guigarage.com/2013/02/change-java-version-on-mac-os/But no effect.
也试过 java 转换器软件:http: //www.guigarage.com/2013/02/change-java-version-on-mac-os/但没有效果。
Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?
知道如何通过单击 1.7 版本来启动 .app 和 .jar 文件等 Java 程序吗?
采纳答案by Nicolas Rinaudo
I believe OS X (at least 10.8) uses the following paths:
我相信 OS X(至少 10.8)使用以下路径:
- JRE:
/System/Library/Frameworks/JavaVM.framework/Versions/Current
- JDK:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
- JRE:
/System/Library/Frameworks/JavaVM.framework/Versions/Current
- JDK:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Those are symlinks, which you can update to point to your 1.7 installation.
这些是符号链接,您可以更新它们以指向您的 1.7 安装。
You can verify this fairly easily:
您可以很容易地验证这一点:
a) run which java
to check which java executable is being executed. In theory, that should be /usr/bin/java
.
a) 运行which java
以检查正在执行哪个 java 可执行文件。理论上应该是这样/usr/bin/java
。
b) run ls -la
on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
on my machine).
b)ls -la
在你的 java 可执行文件上运行,它应该告诉你它指向哪里(/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
在我的机器上)。
I think this should sort your .jar
execution issue. If your Java application is wrapped in a .app
, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub
being used by the .app
.
我认为这应该对您的.jar
执行问题进行排序。如果您的Java应用程序被包裹在一个.app
,我相信这是一个比较复杂:如果没有记错,JAVA的使用将取决于版本JavaApplicationStub
正在使用的.app
。
回答by saganas
You can always add into your profileboth on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:
您始终可以在 Mac 或 Linux 上添加到您的个人资料中。如果不存在,则创建 ~/.profile 文件,然后创建这一行:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.
回答by user3566154
$ edit ~/.profile
#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}
$ java -version
java version "1.8.0_20-ea"
here are the steps:
以下是步骤:
http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html
http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html