Java Applications – Handling SWT Applications in Ubuntu 16.04

16.04gtk3java

It seems that SWT (eclipse based) applications in Xenial (16.04) are mostly broken with default-jdk (ie openjdk 8). This includes Eclipse IDE, Gantproject, etc…

They either won't load, or won't work as expected (never ending operations, …). This is related to the fact that SWT integrates badly with GTK3, and especialy the latest version that ships with Xenial (look for SWT GTK3 in Google for tons of problems and blogs related to the issue).

Most of the time, export SWT_GTK3=0 works around the issue (it falls back to GTK2).

So here is my question: what is the best way to handle this problem for Xenial ?

  • set SWT_GTK3=0 globally for the system (then how is it best done, /etc/bash.bashrc, /etc/environment, ???) ?
  • report the problem to Ubuntu to get it solved before the release ? Then, what are the relevant packages ? (default-jdk, swt-gtk, ???)
    Notice a bug report already exists on the subject: https://bugs.launchpad.net/ubuntu/+source/swt-gtk/+bug/1552764, which I edited to make it more generic and not eclipse IDE only
  • any other option ?

Best Answer

The problem has already been reported to Ubuntu at the link you provided, so nothing more needs to be done there just yet.

If SWT_GTK3=0 works well, you should set it as unglobally as is feasible. There are a few ways to do it (choose the last one that will work for your situation):

  • /etc/environment applies to everything for every user, not just Java programs
  • /etc/bash.bashrc applies to things started from bash for every user, not just Java.
  • ~/.bashrc applies to things started from bash for the current user, not just Java.
  • The following will apply to things started from bash for every user using the java command. Press Ctrl+Alt+T and run the following:
    sudo -i
    mkdir -p /usr/local/bin
    echo '#!/bin/sh' > /usr/local/bin/java
    echo 'SWT_GTK3=0 /usr/bin/java $*' >> /usr/local/bin/java
    chmod a+x /usr/local/bin/java
    exit
    exit
  • The following will apply to things started from bash for the current user using the java command. Press Ctrl+Alt+T and run the following:
    mkdir -p ~/bin
    echo '#!/bin/sh' > ~/bin/java
    echo 'SWT_GTK3=0 /usr/bin/java $*' >> ~/bin/java
    chmod a+x ~/bin/java
    exit