Tuesday, August 17, 2010

Setting up .java files to automatically open with Eclipse on Mac OS X

With the 3.6 (aka, Helios) release of Eclipse, there is now support for opening files from the operating system command line or file browser directly into Eclipse. This has been a long-standing feature request (one of the oldest requests to ever have been implemented, in fact) and many people are happy to have it. Here is a quick tutorial on utilizing this feature under Mac OS X to associate .java files so that they open in Eclipse upon double-click from Finder. Although this demonstrates using .java files, you can do the same for any other file type; as long as your installation of Eclipse has an editor to handle that file type, it should work just fine.

  1. Just to re-iterate, you have to have Eclipse Helios (version 3.6 of the platform) in order to take advantage of this feature. If you don't already have it, go get it.
  2. In Finder, locate a .java file that you'd like to open in Eclipse; right-click (or Control+click if that's the way you roll) and select Get Info

  3. In the Info dialog, under the "Open with:" section, click the drop-down list and select Other...

  4. Here comes the only tricky part about this process.
    In the resulting Finder dialog to select an application, navigate to where Eclipse is installed. You'll see Eclipse.app listed but chances are, it's disabled; you can't select it. You just have to enable it using the Enable: drop-down list at the bottom of the window, as shown here:

    Once you do that, you'll be able to select Eclipse.app.

  5. Before clicking the Add button, decide if you want to select the "Always Open With" option (checkbox). Then click Add.
  6. Back in the "Info" dialog, you can use the Change All... button to associate all .java files with Eclipse. Even if you don't do it now, you an always come back to this dialog and do it later.
That's it. Now when you double-click on .java files they will be opened in the Eclipse installation that you selected. If an instance of Eclipse is already running, that instance will open the file. Otherwise, a new instance will be started.