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.
- dmartin's blog
- Add new comment
- 5150 reads
Weblog
Hey, nice work. The 1.6.1
Did not knew howto run my
The new Java 6 doesn't fix
setting AWT_TOOLKIT=MToolkit
Thanks for the info man.
I'm running on a 64 bit
Thanks D, much appreciated.
Thank you. Running Ubuntu