Fixing Java on Mac Snow Leopard
Monday I was faced with a new situation, Snow Leopard OS X 10.6. There are several issues with Java on the new Mac OSX 10.6 "Snow Leopard". This post will outline the known issues and will provide fixes for several of them (or provide links where fixes are already explained).
- Java 5 is not installed
- Java 5 symbolic links are set to Java 6
- jmap - some aspects of jmap do not function
* I'm still looking for more issues, so if you can add to the list, please add comments, email or twitter.
** I have tested the latest BTrace and it works fine.
Java 5 on Snow Leopard
Whither you agree with the removal of Java 5 or not, it is unbelievable to me that the Java 5 symbolic links are pointing to the CurrentJDK which points to 1.6. For those new to this space the Java version live under /System/Library/Frameworks/JavaVM.framework/Versions . I would advise you to either:
- replace Java 5 using instructions provided at leopard http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard
- simply delete the java 5 symbolic links
- jvms reads through the version directory and reports what it reads of the file system.
- setJava allows you to type in the name of the version and switches JAVA_HOME and path to this version of the JVM.
- unsetJava reverts the set to the original java version
My initial execution of jmap on snow leopard failed with the following error message:
kensipe$ jmap 3407
Attaching to process ID 3407, please wait...
sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol "heapOopSize" in any of the known library names (-)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Debugger attached successfully.
The good news is that the debugger attached successfully :)
Information regarding this issue is scarce. It turns out to likely be an issue with the version of Java that is distributed with snow leopard. The JDK 1.6 rev 14 appears (based on non-confirmed web sources) to have this issue. The latest is JDK 1.6 rev 16 should have the fix, however using the apple distro, we are left waiting for Apple for the fix. Although jmap fails with no arguments it does succeed for certain commands such as jmap -histo 3407.
After replacing the JDK 5 with the leopard distro as advertised above and switching to this version with the script above, jmap works fine. However jdk 5 jmap only works against jdk 5 running applications. It fails against java 6.
The test to see if this is setup correctly for you is: jrunscript -q
After these changes, it appears that Snow Leopard is ready for some hard core Java development. Good Luck and Happy Coding!
Java Switching Script that I use:
# Originally written by Shawn Erickson - shawn at freetimesw.com
# Last Update: 2008y 08m 8d
# The following functions are meant for use with bash shell which is currently the
# default on Mac OS X 10.4 (starting with 10.3 IIRC) unless otherwise configured.
# Good info on why not sym links: http://lists.apple.com/archives/Java-dev/2006/Jan/msg00290.html
# from: http://lists.apple.com/archives/Java-dev/2005/Aug/msg00506.html
### Prompt ###
### Java Environment Functions ###
ls -1 $J_VERSIONS_DIRECTORY | grep ^[0-9].[0-9]
echo "Available JVMs: "$jvms
ls -1 $J_VERSIONS_DIRECTORY | grep ^[0-9].[0-9] # look to remove redundant call
echo " "
echo "Current Java:"
# Validate that the user requested an available JVM present on the system
for jvm in $jvms ; do
if [ "$jvm" == "$@" ]; then
if [ "$target_jvm" == "" ]; then
echo "Unsupported Java version requested"
# If we get here the user asked for a valid JVM, so configure it
echo "Configuring Shell Environment for Java "$@
# First unset any current set java, back to default before doing configuration
# Generate the paths needed for the JVM requested
# We save the original path so we can toggle back if unset
# We save the original JAVA_HOME so we can toggle back if unset
# Update command prompt mode tag to note JVM setting
echo "Current Java:"
if [ "$CURRENT_MODE_STRING" != "" ]; then
echo "Configuring Shell Environment for default Java"
echo "Current Java:"
About Ken Sipe
Ken has been a practitioner and instructor of RUP since the late 1990s, and an extreme programmer and coach since the middle 2000s. Ken has worked with Fortune 500 companies to small startups in the roles of developer, designer, application architect and enterprise architect. Ken's current focus is on enterprise system automation and continuous delivery systems.
Ken is an international speaker on the subject of software engineering speaking at conferences such as JavaOne, JavaZone, Jax-India, and The Strange Loop. He is a regular speaker with NFJS where he is best known for his architecture and security hacking talks. In 2009, Ken was honored by being awarded the JavaOne Rockstar Award at JavaOne in SF, California and the JavaZone Rockstar Award at JavaZone in Oslo, Norway as the top ranked speaker.More About Ken »
November 1 - 3, 2013
Current Topics on the NFJS Tour
- Core Java, JEE
- Dynamic Languages: Groovy, JRuby, Scala, Clojure
- RESTful Web Apps
- Frameworks: Hibernate, Grails, Spring, JSF, GWT, more
- Test Driven Design
- Ajax, Flex, RIA
Why Attend the NFJS Tour?
- » Cutting-Edge Technologies
- » Agile Practices
- » Peer Exchange
- Languages on the JVM: Scala, Groovy, Clojure
- Enterprise Java
- Core Java, Java 7
- Testing: Geb, Spock, Easyb
- NoSQL: MongoDB, Cassandra
- Spring 3
- Automation Tools: Git, Hudson, Sonar
- HTML5, Ajax, jQuery, Usability
- Mobile Applications - iPhone and Android
NFJS, the MagazineMay Issue Now Available
On the road to learningby Raju Gandhi
Refactoring to Modularityby Kirk Knoernschild
RESTful Groovyby Kenneth Kousen
Getting Started with D3.jsby Brian Sletten