Mac OS X Mavericks 中的多个 Java 安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21147720/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:56:05  来源:igfitidea点击:

Multiple Java installations in Mac OS X Mavericks

javaeclipsemacososx-mavericks

提问by prosseek

I downloaded JDK for Mac OS X 10.9.1 from Oracle, but I had to install another Java from Apple site once more, as I couldn't launch eclipse with it.

从 Oracle下载了 Mac OS X 10.9.1 的 JDK,但我不得不再次从 Apple 站点安装另一个 Java,因为我无法用它启动 eclipse。

These are two pages that I referred.

这是我提到的两页。

Now I have three java binaries installed in my computer.

现在我的计算机中安装了三个 Java 二进制文件。

Installation A

安装A

/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Installation B

安装B

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Installation C

安装C

/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

I found that I can easily remove Installation C, however I'm not sure if this is OK.

我发现我可以轻松删除 Installation C,但是我不确定这是否可以。

When I invoked java from command line, it points to Installation A.

当我从命令行调用 java 时,它指向安装 A。

java -version
java version "1.7.0_51"

ls -alF `which java`
lrwxr-xr-x  1 root  wheel  74 Jan 15 09:12 /usr/bin/java@ -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
  • Is there any way to use just one JDK 1.7 for Mavericks by removing two of them safely?
  • 有没有办法通过安全地删除其中两个来为 Mavericks 只使用一个 JDK 1.7?

EDIT

编辑

After some setup and test, I have only one Java (1.6) installed. I have Installation B, and now Installation C is linked to Installation A.

经过一些设置和测试,我只安装了一个 Java (1.6)。我有安装 B,现在安装 C 链接到安装 A。

For using eclipse, I had to make Compiler Compliance level to 1.6 to use it (from the help java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0).

为了使用 eclipse,我必须将 Compiler Compliance 级别设置为 1.6 才能使用它(来自帮助java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0)。

enter image description here

enter image description here

EDIT2

编辑2

This seems to what happened.

这似乎是怎么回事。

  1. Installation of Apple Java

    • Installation A
    • Installation B is a symbolic link to A
  2. Installation of Oracle Java

    • Installation C
    • Changed the Installation B that
      1. Created a /System/Library/Frameworks/JavaVM.framework/Versions/A
      2. Copied files from Installation C (not symbolic link)
      3. Make a symlink Current to Versions/A
  1. 苹果Java的安装

    • 安装A
    • 安装 B 是到 A 的符号链接
  2. 安装 Oracle Java

    • 安装C
    • 更改了安装 B
      1. 创建了一个 /System/Library/Frameworks/JavaVM.framework/Versions/A
      2. 从安装 C 复制的文件(不是符号链接)
      3. 将符号链接设为当前版本/A

I tried to install Oracle Java only by removing Apple Java, but I got installation error, so I guess Apple Java is needed to install Oracle Java.

我试图仅通过删除 Apple Java 来安装 Oracle Java,但出现安装错误,所以我想安装 Oracle Java 需要 Apple Java。

采纳答案by prosseek

It seems like that the oracle JDK can be just removed. For eclipse, I could add Installation A as a default JRE from Java Build Path -> JRE System Library -> Installed JRES -> Add ...

好像可以直接删除oracle JDK。对于 Eclipse,我可以从 Java Build Path -> JRE System Library -> Installed JRES -> Add ... 添加安装 A 作为默认 JRE

enter image description here

enter image description here

回答by MariuszS

Specify the JVM for Eclipse

为 Eclipse 指定 JVM

You can specify JDK version for usage with Eclipsein eclipse.ini. This will resolve problem with starting Eclipse.

您可以在Eclipse使用指定的JDK版本eclipse.ini。这将解决启动 Eclipse 的问题。

-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java

Warning: Add this configuration before-vmargs.

警告:在此之前添加此配置-vmargs

Master your Java Environnement with jenv

使用 jenv 掌握您的 Java 环境

It is much easier to maintain multiple JDK versions with jenv.

使用jenv维护多个 JDK 版本要容易得多

jenv is for a equivalent of rbenv, but for Java environnement. It allow to easily switch between several JDKs installations(already presents), and configure which one to use per project.

jenv 相当于 rbenv,但用于 Java 环境。它允许在多个 JDK 安装(已经存在)之间轻松切换,并为每个项目配置使用哪个。

Eclipse JDK

日食JDK