Friday, May 8, 2009

Eclipse 3.5 (Galileo) on Java 7

Some time ago I blogged about running Eclipse (Ganymede) on SoyLatte. Since then there has been little improvement in the state of Java on the Mac. Apple has released a Java 6 for Mac, but it's a 64-bit only VM which crashes regularly when running Eclipse. Having heard about recent improvements in performance for 64-bit VMs using pointer compression (PDF paper), I decided to have another look at launching Eclipse with an OpenJDK-based VM such as JDK7. After a few false starts I managed to get it working. Here's what I did:

First, to get JDK7 on my machine. I followed these instructions to build JDK 7 from source. The instructions didn't work perfectly for me -- but they were pretty good. Basically followed everything verbatim with the exception that I had to install MacPorts and use it to get wget.

With a 32-bit JDK7 on my machine, now to use it to start Eclipse. I downloaded the latest I-build of 32-bit Eclipse 3.5 from here (Look for '3.5 Stream Integration Builds').

Using a combination of jconsole and guesswork I came up with this shell script to start Eclipse:


JDKPATH=/Users/dgreen/Documents/packages/jdk7-32bit-2009-05-08
DEBUG_OPTS=
# DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y
MEM_OPTS=-Xms1024m\ -Xmx1536m\ -XX:MaxPermSize=256m
ECLIPSE_LOC=/Users/dgreen/Downloads/eclipse
WORKSPACE=/Users/dgreen/Documents/workspace

$JDKPATH/bin/java $DEBUG_OPTS \
-cp $ECLIPSE_LOC/plugins/org.eclipse.equinox.launcher_1.0.200.v20090429-1630.jar \
-XstartOnFirstThread $MEM_OPTS \
-Dorg.eclipse.swt.internal.carbon.smallFonts \
-Djava.library.path=$ECLIPSE_LOC/Eclipse.app/Contents/MacOS/lib \
-Dswt.library.path=$ECLIPSE_LOC/Eclipse.app/Contents/MacOS/lib \
org.eclipse.equinox.launcher.Main \
-os macosx -ws cocoa -arch x86 \
-showsplash -launcher $ECLIPSE_LOC/Eclipse.app/Contents/MacOS/eclipse \
-name Eclipse \
--launcher.library $ECLIPSE_LOC/plugins/org.eclipse.equinox.launcher.cocoa.macosx_1.0.0.v20090429-1630 \
-startup $ECLIPSE_LOC/plugins/org.eclipse.equinox.launcher_1.0.200.v20090429-1630.jar \
-data $WORKSPACE \
-keyring /Users/dgreen/.eclipse_keyring -consoleLog -showlocation \
-vm $JDKPATH

Note that all of the above should appear on one line: your browser may split it into multiple lines.

After starting Eclipse as above I saw the following stack trace on startup:


java.lang.UnsatisfiedLinkError: no swt-pi-cocoa-3547 or swt-pi-cocoa in swt.library.path, java.library.path or the jar file
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:248)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:159)
... snip ...

To solve the problem I extracted all of the *.jnilib files from org.eclipse.equinox.launcher_*.jar and put them in a lib folder. I then renamed all of those *.jnilib files in the lib folder so that they had *.dylib file extensions. I ended up with a file structure as follows:


david-greens-macbook-pro:MacOS dgreen$ pwd
/Users/dgreen/Downloads/eclipse/Eclipse.app/Contents/MacOS <--- where I put the files
david-greens-macbook-pro:MacOS dgreen$ ls -l *.sh lib
-rwxr-xr-x@ 1 dgreen staff 1100 8 May 15:47 eclipse.sh <--- the startup script

lib: <---- the lib folder for shared libraries
total 2296
-rw-r--r-- 1 dgreen staff 37104 8 May 14:20 libswt-awt-cocoa-3547.dylib
-rw-r--r-- 1 dgreen staff 287116 8 May 14:20 libswt-cocoa-3547.dylib
-rw-r--r-- 1 dgreen staff 539240 8 May 14:20 libswt-pi-cocoa-3547.dylib
-rw-r--r-- 1 dgreen staff 300428 8 May 14:20 libswt-xulrunner-cocoa-3547.dylib

Trying the shell script again, Eclipse started up and ran beautifully! Once again I'm running Eclipse with a newer-than-Apple-will-give-me VM, this time JDK 7!! My next step is to compile a 64-bit JDK7 and see if it works too... I have high hopes.

7 comments:

Daniel Spiewak said...

Eclipse does work on Apple's 1.6 VM, it just requires adding the following tweaks to your eclipse.ini: http://paste.pocoo.org/show/116634/

Good luck with JDK 7 though!

David Green said...

@Daniel Spiewak thanks for the tip. In fact, I've been doing that and found that I come across new ones on a regular basis. For example, I had to add this one:
-XX:CompileCommand=exclude,java/text/SimpleDateFormat,subParseZoneString

For me, a VM crash is a big problem, not only in terms of data loss and time lost restarting Eclipse; it breaks my flow and concentration, which for me is a showstopper.

Eric Rizzo said...

I run Eclipse 3.5 on my MacBook Pro using the 64-bit 1.6 JVM all day, every day and don't recall ever seeing a VM crash. Is it possible you have some non-standard configuration? Do you have the latest Java update from Apple?

David Green said...

@Eric Rizzo I agree, I use the 64bit 1.6 JVM a lot and it's no longer crashing for me. That wasn't the case when I wrote this article in May 2009.

BTW, I've recently published a related article: Eclipse 3.6 on OpenJDK on Mac OS X

Eric Rizzo said...

Wow, I didn't notice the article date; it just showed up on Planet Eclipse recently - maybe because you updated the content...?
Sorry about that noise.

David Green said...

@Eric Rizzo no problem! I noticed the Planet Eclipse problem too, and filed bug 300087: Updated articles are republished on planeteclipse.org

JamesB said...

I can't get Eclipse 3.7M6 running with latest OpenJDK 7... Mailing list seems to show others are having the same issue. I've filed two bugs:
https://bugs.openjdk.java.net/show_bug.cgi?id=100176
https://bugs.eclipse.org/bugs/show_bug.cgi?id=339788

Anyone else had more luck with recent releases?