Opening files in Eclipse from the command line, or through file associations
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. 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. The remaining work, targeted for 3.6 M6, is described in bug 301030.
How To Enable
There are platform-specific differences as described below.
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.
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 <file to open>
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 <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:
- 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
- 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.
- 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