简体   繁体   English

更改java版本(Mac)

[英]Change java version (Mac)

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. 1.6.0设置为默认值。 How can I make my java programs to run 1.7? 如何让我的java程序运行1.7?

Tried to add: 试图添加:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

to my .zshrc file. 到我的.zshrc文件。 But this seems to only change the path for my terminals java command. 但这似乎只改变了我的终端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程序吗?

I believe OS X (at least 10.8) uses the following paths: 我相信OS X(至少10.8)使用以下路径:

  • JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
  • JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 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. a)运行which java来检查正在执行哪个java可执行文件。 In theory, that should be /usr/bin/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)在java可执行文件上运行ls -la ,它应该告诉你它指向的位置( /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java在我的机器上)。

I think this should sort your .jar execution issue. 我认为这应该排序你的.jar执行问题。 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 . 如果您的Java应用程序包含在.app ,我相信它有点复杂:如果内存服务,则使用的java版本将取决于.app使用的JavaApplicationStub

You can always add into your profile both on Mac or Linux. 您始终可以在Mac或Linux上添加到配置文件中 Just create if doesn't exist ~/.profile file and there this line: 只是创建如果不存在〜/ .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 . 这应该有效.zshrc和.bash_profile仅在终端窗口打开时加载,并在图形环境启动时加载。

$ 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

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

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