How to run Eclipse from the command line in OS X (and Windows and Linux)

EclipseosxiconThe Mac is very easy to use due to its innovative packaging system for applications, where it hides an entire tree of directories inside one file/icon. With Eclipse, this shows up as the Eclipse icon that we know and love.

However, if you’re a hardcore programmer, then you really should get your hands dirty with the command line via OS X’s Terminal. This lets you get down to the UNIX core. When you go into your Eclipse install directory, you’ll find a nice executable named appropriately enough: “eclipse”. Well, it’s actually just a symbolic link into the Eclipse.app (the nicely packaged Eclipse application that I mentioned above.)

If you just type “eclipse”, you’re in for a rude awakening, as you won’t be able to interact with the UI and you’ll be forced to Control-C. The reason why is due to an obscure implementation of how threading works in the Apple Java Runtime and how it interacts badly with SWT’s (and thus Eclipse’s) expectation of how it should be running.

The solution, however is simple:

./eclipse -vm Eclipse.app/Contents/MacOS/java_swt


The reason why this works is because of a special version of the Java launcher that accommodates SWT’s needs on OS X. You can find out more at the Eclipse Bugzilla, bug 40003.

Here is a nicer version, which lets you see System.out and System.err, as well as Eclipse debug statements, and shows how you can pass in arguments to the underlying VM:

./eclipse -vm Eclipse.app/Contents/MacOS/java_swt -debug -consoleLog -vmargs -Xmx256M

Windows users: You can also run Eclipse from the command line, but you have to make an eclipse.bat file by hand. In this bat(ch) file, include:

eclipse.exe -debug -consoleLog -vmargs -Xmx256M

Linux users: You probably already Eclipse from the command line and you probably don’t need my help doing it. ;) But just in case you do, use something like:

./eclipse -debug -consoleLog -vmargs -Xmx256M

Windows and Linux users: You can supply the -vm parameter as well if you want to run Eclipse using another VM, like the JDK 1.5 for example.

You can find out more information about command line arguments to Eclipse in the the Eclipse runtime options page in the Eclipse Help.

2 thoughts on “How to run Eclipse from the command line in OS X (and Windows and Linux)

  1. Andre Weinand

    Starting with JVM 1.4.2_4 Apple provides a new Java VM option (-XstartOnFirstThread) to address the (non-standard) threading issue in MacOS X. With it it is no longer necessary to pass the java_swt program via the -vm command line option to ./eclipse.
    So in the Eclipse 3.1 stream you can launch eclipse like this:

    ./eclipse -consoleLog -vmargs -XstartOnFirstThread …

    Please note that all arguments preceeding the “-vmargs” are passed to Eclipse and all arguments following the “-vmargs” are passed to the VM itself (/usr/bin/java).

  2. Rashmi

    To run Eclipse on windows from the command line, I use the following:
    eclipse.exe -vm c:/jdk/jdk1.4.2/bin/javaw.exe -vmargs -Xm256M -Xmx500M