DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. Installing Java 7 on Mac OS X

Installing Java 7 on Mac OS X

Vineet Manohar user avatar by
Vineet Manohar
·
Mar. 18, 11 · Interview
Like (0)
Save
Tweet
Share
62.15K Views

Join the DZone community and get the full member experience.

Join For Free

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/

Mac OS X Java (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Building Microservice in Golang
  • What Is Advertised Kafka Address?
  • Introduction to Spring Cloud Kubernetes
  • Orchestration Pattern: Managing Distributed Transactions

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: