Channels ▼

Eric Bruno

Dr. Dobb's Bloggers

Java 7 Preview for Mac OS X

October 19, 2011

Oracle announced the availability of Java SE 7 in beta form for Mac OS X at JavaOne earlier this month. Here, I'll show you how to get started using Java SE 1.7 on your Mac today, while still maintaining your Java SE 1.6 installation as well.

First, download the Java 7 disk image (.DMG file) here: Next, follow these instructions, which are also posted on the download page:

  1. Create the directory /Library/Java/JavaVirtualMachines, if it does not exist already, via this command:
    > sudo mkdir /Library/Java/JavaVirtualMachines

  2. Open the Java 7 DMG file you downloaded above.

  3. When the installer opens, simply drag the icon on the left to the JavaVirtualMachines folder within the installer window (see screen shot below). In order for the installer to write to the folder, you'll need to authenticate by providing your password.


  4. Verify that both Java 6 and Java 7 are installed on your machine by doing the following:
    • Browse to the Java 7 folder in the Finder within the /Library/Java/JavaVirtualMachines folder you created (see screen shot below).


    • Double-click the icon labeled "JDK 1.7.0 Developer Preview", which will open Java Preferences. Alternatively, you can find Java Preferences in the Applications/Utilities folder.

    • You should see your previously installed versions of Java within this Window, as well as the Java SE 7 Preview entries, one for 32bit and the other for 64bit (see screen shot below).


The entry at the top of the list will be the default version of Java chosen when you execute it from the command line. You can leave Java SE 7 where it is, or make it the default by moving it up to the top of the list.

Build Java SE 7 Applications

To use the Java 7 installation for new projects, you'll need to create a new Java platform within your favorite IDE. In NetBeans, for example, choose "Java Platforms" from the Tools menu, click the Add Platforms button, and navigate to the Java 7 Preview folder. The full path should be /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home (see screen shot below).


Click the Next button, provide a name for the platform (the default should be "JDK 1.7"), and then click Finish. From now on, you can choose the JDK 1.7 platform for new or existing projects by changing the platform in the project Properties window. To do this, right-mouse click on the project name, choose "Properties" from the popup menu, choose "Libraries" from the Categories section on the left, and then click on the Manage Platforms button on the right. There should be an entry for each Java platform, including the one you just created (see screen shot below).


For Eclipse, the process is similar. To begin, open the Preferences window, expand the "Java" entry within the list on the left, and click on "Installed JREs". You should see your existing JRE entries; click the Add button on the right to add a new one. As for JRE type, choose "Standard JRE," and then click Next. In the next window, provide the path to Java SE 1.7 (Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home), and provide a name, i.e. "JDK 1.7".


Click Finish, then OK, and you're all set. You can check the checkbox for the new JDK if you want it to be the default for new projects. To change the JDK for existing projects, you'll need to update the Java compiler and JDK used in the project's properties much like you would for NetBeans.

If you didn't make Java 1.7 the default in Java Preferences, you'll need to provide the explicit path to Java 7 at the command line. For instance:

> /Library/Java/JavaVirtualMachines/JDK\ 1.7.0\ Developer\ Preview.jdk/Contents/Home/bin/java -version

That looks terrible, and it's a pain to type even as you tab through to automatically fill in the path names. I suggest creating an environment variable, via the following command, and adding it to /etc/profile:

export JDK7="/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/bin/"

Then just type "$JDK7/java" -version, or the command-line for your application, to launch Java SE 7.

Now you're ready to explore the world of Java SE 1.7, with its new Fork/Join framework, File APIs, and lots more. Keep checking here for the latest on Java 7 programming.

Happy coding!

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.