ADC Home > Reference Library > Technical Q&As > Java > Design Guidelines >

Important Java Directories on Mac OS X


Q: I am porting a Java product to Mac OS X. What are the equivalents for directories and paths common to JDK installations on other platforms?

A: Since J2SE is a preinstalled component on every copy of Mac OS X, the location and structure of the Java VM is controlled and consistent. User input should not be required to retrieve information on Java-related paths and directories.

Java Home. Many Java applications require the identification of a "Java Home" directory during installation. The equivalent on Mac OS X should always be /Library/Java/Home. This is actually a symbolic link to the current installed J2SE version, and allows access to the bin subdirectory where command line tools such as java, javac, etc. exist as expected. The advantage of using this link, as opposed to its target, is that it will be maintained and updated when a new version of Java is downloaded via Software Update or installed with a newer version of Mac OS X. For this reason, it is important that developers do not install files below the Java Home, as the actual directory referenced by the link will be lost with subsequent updates when the link is updated by newer versions of Java.

Extension Libraries. Java software on other platforms often makes use of the lib/ext directory within a JDK installation to store support class or jar files. While the Mac OS X java home also contains a lib/ext directory, it is not recommended that developers directly make use of it for the same reason mentioned above. Similar to the java home situation, Apple has provided standardized paths for extension libraries to be placed. The /Library/Java/Extensions directory can be used for additional jar files or JNI libraries that need to be placed on the system classpath. For more controlled access, a ~Library/Java/Extensions directory off of a given user's home directory can be used for user-level installation of support libraries. Items placed in either of these directories do not need to be named in an application's classpath and will be available to all applications run under the applicable scope (user-level or system-level, depending on which directory is used).

Please note that these extension directories are for jar files and JNI libraries only. Directories of classfiles, even if properly laid out to match your packages, are not picked up. If you want to use these provided extension directories, package your support Java classes into jar files. JNI libraries can go in as-is.

User Preferences. Many applications choose their own installed directory structure for storing settings and user preferences. Others try to make use of whatever preference system exists on the host platform. In the latter case, on Mac OS X, user preferences for an application are typically stored in the ~/Library/Preferences directory, if those preferences are to be on a per-user basis. This directory could be reached from Java code by appending the String "Library/Preferences" to the user.home System property. An application that should have global preferences across all users could instead reside in /Library/Preferences from root.


[Oct 21, 2003]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.