Vineet Manohar is CTO / Co-Founder of online Car Search Engine, iSeeCars.com. Vineet is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

Installing Java 7 on Mac OS X

03.18.2011
| 54810 views |
  • submit to reddit

While you can download the binaries for Java 7 for Windows and Linux from here, the instructions for setting up Java 7 for Mac OS X are a lot more tedious.

Here are the official instructions for Mac OS X: http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port

You can follow the instructions line by line and get Java 7 installed on your machine. However, these are the things that might go wrong:

Missing binaries in /bin

The installation expects a bunch of binaries to be present in /bin. However, on my Mac OS X, these binaries were present in /usr/bin/. My workaround was to create symlinks in the /bin directories to make the build happy.

 cd /bin/  
ln -s /usr/bin/sed
ln -s /usr/bin/grep
cd /bin/
ln -s /usr/bin/sed
ln -s /usr/bin/grep

Repeat the above for each binary that is reported missing in /bin.

Missing jni.h

Make sure that the version of XCode is 3.2.5 or more. I had a 3.2.4 version and that didn’t work.

Building JTReg did not work due to a known bug

It is mentioned in the JTReg build documentation but easy to miss it. The following does not work due to a know bug:

make -C make  
make -C make

Instead try this:

make -C make build  
make -C make build

Wrong installation directory in the official instructions

The official instructions ask you to do this:

mkdir -p ~/Library/Java/JavaVirtualMachines
cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk ~/Library/Java/JavaVirtualMachines

That didn’t work for me. Here’s what worked for me:

   mkdir -p /System/Library/Java/JavaVirtualMachines  
cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk /System/Library/Java/JavaVirtualMachines
mkdir -p /System/Library/Java/JavaVirtualMachines
cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk /System/Library/Java/JavaVirtualMachines

Finally, setting up env vars

The easiest way to make confirm that Java 7 is successfully installed is:

/usr/libexec/java_home --version 1.7  
/usr/libexec/java_home --version 1.7

The output of the above should be:

/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home  
/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

Then type ‘java -version’ against the above installation

  /System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java -version  
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-root_2011_03_16_17_41-b00)
OpenJDK 64-Bit Server VM (build 21.0-b03, mixed mode)
/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-root_2011_03_16_17_41-b00)
OpenJDK 64-Bit Server VM (build 21.0-b03, mixed mode)

Since I use Java 1.6 on the same machine, I saved the 1.7 path as follows:

   export JAVA7_HOME=/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home  
export JAVA7_HOME=/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

This lets me conveniently switch to Java7, when I need to, and back:

  export JAVA_HOME=$JAVA7_HOME  
export JAVA_HOME=$JAVA7_HOME

Switch back:

  export JAVA_HOME=$JAVA6_HOME  
export JAVA_HOME=$JAVA6_HOME

Using Java7

Simplest way to use test Java7 is via command line

   export JAVA_HOME=$JAVA7_HOME  
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME=$JAVA7_HOME
export PATH=$JAVA_HOME/bin:$PATH

Compile

  javac Test.java  
javac Test.java

Run

 

java Test 

From http://www.vineetmanohar.com/2011/03/installing-java-7-on-mac-os-x/

Published at DZone with permission of Vineet Manohar, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Ron Kita replied on Mon, 2011/06/13 - 2:14pm

hi, i am a retired programmer who uses Java on a MacBook Pro. The software i am writing is a finite state modeling tool. anyway, i run it on a windows machine using cgywin and on mac. there must be a recent update to java 1.6 on my mac that is terribly wrong. prior to , say 3 months ago, the 64 bit version ran as fast as java32 on windows, now it is probably hundreds of times slower. i can see java 1.6 thrashing , seems like some part of the memory management is messed up. Also suspending and resuming threads causes random crashes. i do not see these problems under windows. i spent a few days thinking i caused the problem, but when i re-installed java 1.5 on my mac, the performance was back to where it had been. now my problem is that jdb does not work (version 1.5.0_19) under 1.5 and i have no idea why. any ideas? Where can i find jdb source? just a note: even running 1.5 , java-32 is slower than java-32 on windows. this in spite of the fact my windows machine is about 7 year old amd technology. i use flags Xmx1024m for 32 bit and Xmx3024m for java-64 (on mac). The modeling system can run hundreds of thousands of recursive calls on large models so i am not surprised about the memory. on another note, simple modeling problems are not noticeably slow on 1.6. it is only intensive one that turn bad. do you think these problems are fixed in java 1.7 for a mac or do i inherit other problems? thanks

Ankit Dhingra replied on Tue, 2012/07/10 - 7:50am

I see that there is a dmg available at http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u4-downloads-1591156.html

Wont this work out of the box? 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.