Sunday, November 18, 2012

Eclipse fails to start due to missing SWT native libraries

After installing Oracle (Sun) JDK 1.8 and removing OpenJDK on Ubuntu 12.04, Eclipse stopped starting. Below is the startup log captured at failure time.


eclipse.buildId=I20110613-1736
java.version=1.8.0-ea
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments: -os linux -ws gtk -arch x86_64

!ENTRY org.eclipse.osgi 4 0 2012-11-18 11:45:37.406
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
  no swt-gtk-3740 in java.library.path
  no swt-gtk in java.library.path
  Can't load library: /home/xxx/.swt/lib/linux/x86_64/libswt-gtk-3740.so
  Can't load library: /home/xxx/.swt/lib/linux/x86_64/libswt-gtk.so

  at org.eclipse.swt.internal.Library.loadLibrary(Library.java:285)
  at org.eclipse.swt.internal.Library.loadLibrary(Library.java:194)
  at org.eclipse.swt.internal.C.<clinit>(C.java:21)
  at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
  at org.eclipse.swt.widgets.Display.<clinit>(Display.java:132)
  at org.eclipse.ui.internal.Workbench.createDisplay(Workbench.java:695)
  at org.eclipse.ui.PlatformUI.createDisplay(PlatformUI.java:161)
  at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:95)
  at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

Diagnosis

Installing Oracle JDK changed the system default Java runtime. Eclipse on Ubuntu 12.04 relies on SWT native libraries compatible with OpenJDK, which were no longer resolved after the JVM switch.

Resolution

Manually link the system SWT libraries into Eclipse’s SWT cache directory.

Ubuntu 12.04 (64-bit):

ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/

Ubuntu 12.04 (32-bit):

ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86/

Alternative

Switch back to the OpenJDK runtime expected by the installed Eclipse build:

sudo update-alternatives --config java