How to get Java Swing apps working under Beryl or Compiz, including Java Web Start

Update: I'm getting reports that this has been fixed in Java 1.6 (aka Java 6).  So, I tested this with the latest Java 1.6 32-bit in Ubuntu Edgy, and apps seem to be working fine under Beryl.  So, you may not need to go to all the trouble below.  The latest Java 1.6 for AMD64 on Ubuntu Edgy, however, still doesn't work for me under Beryl.


 

At this time, Java Swing apps won't run properly under Beryl or Compiz.  The app comes up, but it comes up completely blank.  It's a known issue, and Java engineers are working on it.  But until it hits my box, I still need to run Java, and I'm definitely not giving up Beryl.

The following solution is tested on Ubuntu.  But, if you adjust the paths as necessary, the same general thing should work on other Linux distributions.  The solution is to pass an environment variable to Java, AWT_TOOLKIT=MToolkit.  The best way I've found to do this is to create a wrapper script in /usr/local/bin.

AMD64 users should first get Java 32 bit set up, following the instructions in my previous blog entry.  I honestly don't know why this doesn't work on 64 bit Java, but for me it seg faults.  You can try the instructions below using a 64 bit JVM.  If it works for you on a 64bit JVM please let me know.  Maybe I have something set up wrong.

Java Wrapper script for Beryl/Compiz

sudo gedit /usr/local/bin/java

And in it, put (the following is only two lines, even though there may be wrapping to three):

#! /bin/bash
XLOCALELIBDIR=/usr/lib32/X11/locale/ AWT_TOOLKIT=MToolkit /usr/lib/jvm/ia32-java-1.5.0-sun/bin/java ${*}

The path to the java binary is probably not correct for your system.  Adjust as necessary.  If you are on Ubuntu chances are it is something like /usr/lib/jvm/{JAVA_VERSION)/bin.  In that case you can see which versions you have by running:

ls /usr/lib/jvm

You also need to make that file executable:

sudo chmod +rx /usr/local/bin/java

About that XLOCALELIBDIR setting.  This is to overcome an error I was experiencing.  I've not yet determined if this is something I've messed up somehow, or if this is a real problem everyone will experience.  I also get similar whining from Perl.  If you try without the XLOCALELIBDIR setting, and it works, please let me know and I will remove it from this How To.

You may need to adjust the location of your Java binaries, depending on the version of Java you've installed.  Now, java apps should run by typing "java MyClass" or "java -jar myjar.jar".  For installed Java programs, you may need to edit their menu entries to use this java wrapper.  If they use a shell script, you may have to edit that.

Java Web Start Wrapper script for Beryl/Compiz

To get javaws working, you can create a similar script in /usr/local/bin.  

sudo gedit /usr/local/bin/javaws

And in it put (again, the following is two lines only):

#! /bin/bash
XLOCALELIBDIR=/usr/lib32/X11/locale/ AWT_TOOLKIT=MToolkit /usr/lib/jvm/ia32-java-1.5.0-sun/bin/javaws ${*}

Again, adjust the path to the javaws binary as necessary.  Also make this file executable:

sudo chmod +rx /usr/local/bin/javaws

For Java Web Start in Firefox or any other browser, when you click on a .jnlp link you will be prompted, and you should tell the browser to open the file with "/usr/local/bin/javaws". 

That's all there is to it.  You should now have Java and Java Web Start working under Beryl or Compiz.

  1. Keith c (not verified)
    Mon, 03/19/2007 - 5:18pm
    Hey, nice work. The 1.6.1 jdk beta also seems to solve the issue (sorry, dunno the URL off the top of my head). I'll give your solution a shot tho.
  2. polarizer (not verified)
    Wed, 03/21/2007 - 2:12am
    Did not knew howto run my java "Looking Glass Desktop" under Compiz or its fork Beryl until now :) Thx for sharing the information polarizers 2 cents
  3. Dr.Q (not verified)
    Thu, 03/22/2007 - 9:48am
    The new Java 6 doesn't fix this problem for me. I'am using Ubuntu Edgy 32-bit. Also setting AWT_TOOLKIT=MToolkit doesn't work for me. Any suggestions?
  4. Anonymous (not verified)
    Wed, 08/15/2007 - 12:52pm
    setting AWT_TOOLKIT=MToolkit can cause Sun java to abend: java 1.5.0_12: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6585673 java 1.6.0_1: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570063
  5. Fred Biehl (not verified)
    Wed, 10/17/2007 - 7:30am
    Thanks for the info man. Helped me alot! running java sun 1.5.0_11 + edgy + compiz fusion. Jude app Works perfectly now. Thank you Fred
  6. iLuvatar (not verified)
    Thu, 03/27/2008 - 6:15am
    I'm running on a 64 bit fedora, and I could resolve some issues by installing 32 bit libXp. It seems like 32 bit apps work if I export AWT_TOOLKIT, 64 bit apps don't. I haven't found out yet why.
  7. Byron (not verified)
    Thu, 04/17/2008 - 1:22am
    Thanks D, much appreciated. Ubuntu 7.10 AMD64 running Compiz/Beryl, this got Oanda FX trading software running. Thanks!
  8. Thadeus (not verified)
    Mon, 07/14/2008 - 7:56pm
    Thank you. Running Ubuntu 8.10 with Compiz-Fusion and Mac4Lin. I had problems where my swing windows would work, but anything that was JOptionPane would not display. I applied your patch above with some modification and it works perfectly. In the JRE bin folder /usr/lib/jvm/java-6-sun/jre/bin are the locations for java and javaws. I just renamed them to java.ex and javaws.ex and created new files for java and javaws and put your script in them, and it works flawlessly. Your method of putting them in /usr/local/bin did NOT work for me.
  9. Anonymous (not verified)
    Mon, 03/01/2010 - 3:55pm
    Awesome tip, thanks very much! That's solved a problem that was giving me considerable grief... I just added your AWT_TOOLKIT=MToolkit as an export in my bashrc, and start javaws from the shell. Works a treat! Running ubuntu 9.10 on an AMD 64 with compiz...