Multiple Java installations in Mac OS X Mavericks

淺唱寂寞╮ 提交于 2019-11-27 01:59:28

问题


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.

These are two pages that I referred.

  • Installing Java on OS X 10.9 (Mavericks)
  • http://support.apple.com/kb/DL1572?viewlocale=en_US

Now I have three java binaries installed in my computer.

Installation 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

/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

/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.

When I invoked java from command line, it points to Installation 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?

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.

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).

EDIT2

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

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.


回答1:


Specify the JVM for Eclipse

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

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

Warning: Add this configuration before -vmargs.

Master your Java Environnement with jenv

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

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.

Eclipse JDK

  • Setting JDK in Eclipse



回答2:


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 ...



来源:https://stackoverflow.com/questions/21147720/multiple-java-installations-in-mac-os-x-mavericks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!