Background

Based on work in SWT (bug 201154) and the native launcher (bug 178927), the Eclipse IDE now supports opening a file from the command line, or opening a file that has been associated with the Eclipse executable (bug 4922).

 

If an instance of Eclipse is already running, that instance will open the file. Otherwise, a new instance will be started. As of 3.6 M5, this feature is not fully finished and not enabled by default, but we encourage those interested in this feature to give it a try and provide feedback, for example on the bugs linked to above. The remaining work, targeted for 3.6 M6, is described in bug 301030.

How To Use the Feature

There are platform-specific differences as described below.

Mac Cocoa

On Mac Cocoa, the feature works without having to tweak anything. You can right-click (or Ctrl-click) on a file and pick "Open With", then select Eclipse.

Linux GTK

To enable the feature on Linux GTK, as of 3.6 M5, the Eclipse IDE needs to be launched with a command line that looks like:

eclipse --launcher.openFile <absolute path of file to open>

You can also right-click on a file, select "Open With>Other Application" and enter a custom command:

'<path to eclipse executable>' --launcher.openFile

Windows

To enable the feature on Windows, as of 3.6 M5, the Eclipse IDE needs to be launched with a command line that looks like:

eclipse.exe --launcher.openFile <absolute path of file to open>

On Windows, there are several ways to associate a file type with Eclipse such that you can "Open With" Eclipse, or double-click on a file that has Eclipse defined as the default application:

Batch file

Create a .bat file that passes the openFile option as shown below, then use "Open With" and select the .bat file:

eclipse.exe --launcher.openFile %1

Change eclipse.ini

Add "--launcher.openFile" to your "eclipse.ini" file, in a line immediately above "-vmargs". Then use "Open With" and select "eclipse.exe". This has the disadvantage that you won't be able to start the eclipse.exe from the command line or a .bat file with additional arguments - the first argument you pass will be interpreted as a file.

Registry

Change the Windows registry similar to how an installer would do it, by inserting a key under HKEY_CLASSES_ROOT\<file type>\Shell\Open\Command and a key for the file type under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<.extension>\OpenWithProgids (good luck! :-)

 

Original entry by Boris

More articles :

» Commands Tutorial

As you would have seen, there are two different ways to contributing to the Workbench: Actions and Commands. Although Commands are newer and advanced, I've always preferred using Actions, simply because of my comfort level in using them. Now that...

» Creating the defacto RCP Mail application

  In many of the RCP related tips in this website and other sites, the starting point would be this one liner "Create the RCP Mail application". Instead of repeatedly this step in those tips, I've put the steps in this item. Step 1: Open the "New"...

» Progress Bars in Eclipse UI

In the "" article, I said the top most mistake is running long running operations in the UI thread. Assuming that you are running it in a non-UI thread, how to show the progress of the execution? Obviously thru progress monitors. But how many...

» Opening an editor without IFile

When we use Eclipse, we are used to the notion of editors operating on a workspace file. But workspace and resources are optional for an RCP application. You might have to invoke an editor on a non-file object like a database record or an in-memory...

» Contributing Workbench Wizards thru Commands

You must have been used this JDT toolbar quite often.The New Class tool item is contributed as an Action in (id "org.eclipse.jdt.ui.actions.NewTypeDropDown"), and then the Menu on the Action is contributed via . In this tip, let us see how to do...

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License