Thursday, 9 October 2008

NetBeans - blank dialog box fix

I've been using LinuxMint 5 for some weeks now, and a very fine distro it is, too. I've noticed that NetBeans 6.1 starts and runs a great deal faster on Mint than on Windows XP - the difference is quite significant. I've been wondering why that is, given that this is Java and therefore presumably only the low-level loaders and file-system interactions differ across platforms. That's just a passing observation and not the point of this post.

I found one annoying thing happening occasionally (but often enough to be irritating): NetBeans dialog boxes would appear completely empty. Take a look at the screenshot:



There didn't seem to be any pattern to this behaviour; it wasn't always the same dialog, and if you closed the dialog and opened it again it would appear normally. Not good.

Well, it turns out this is known problem when using the Compiz window manager on Linux - a quick search revealed a good post on the NetBeans forums about this subject. The answer is to use the latest JRE / JDK build as it addresses this compatibility issue. I decided to download and install JDK 6u10 RC and give it a try.

To get NetBeans to use the newer JDK, you can do one of two things:
  1. Edit the NetBeans configuration file (in <installationFolder>/etc/netbeans.conf) and change the path pointed to by netbeans_jdkhome
  2. Change your system default Java installation.
Not very keen on (1) - feels like I'm hiding a workaround in just one application's config, but the problem exists for any Java application I run on this system.

So I decided to do (2). It worked perfectly, so thought I'd share the steps I used to do it. First, where is Java actually installed on the filesystem? If you do 'which java' in a console, it will report /usr/bin/java. But if you look closely, this is just the first step in an indirection; the ls tool reveals:

$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2008-10-01 06:55 /usr/bin/java -> /etc/alternatives/java

And /etc/alternatives/java is another step:

$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2008-10-01 06:55 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java

And the /usr/lib/jvm/java-6-sun file is actually a symbolic link to the actual Java installation folder, which is in the same folder. That's a lot of indirection, and I am quite sure there are good reasons for all of it, but I haven't time to learn all of them. There is a very detailed post by Anthony Richardson which patiently explains how to create a proper DEB package from the JDK download; this is almost certainly a good idea.

I chose to exploit the fact that the last step in the indirection chain is that symbolic link file. By unpacking the JDK directory into /usr/lib/jvm and getting the java-6-sun link to point to the new JDK folder, I decided I could replace 6u6 with 6u10, system-wide.

However, there is another file in this folder: the .java-6-sun.jinfo file (this is a '.' file - you'll only be able to see those if you use the a switch with ls (e.g. ls -al) or View / Show Hidden Files in Nautilus). Looking inside it, only the first line appears to contain version-specific stuff - everything below uses paths which use the symbolic link:

name=java-6-sun-1.6.0.06
alias=java-6-sun
priority=63
section=non-free

jre ControlPanel /usr/lib/jvm/java-6-sun/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-6-sun/jre/bin/java
jre java_vm /usr/lib/jvm/java-6-sun/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-6-sun/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-6-sun/jre/bin/jcontrol
<snip>

I decided to leave this as-is for now, and edit it later if required. So, in summary here is what I did:
  1. Copied the JDK 6u10 contents into /usr/lib/jvm.
  2. Went to the directory /usr/lib/jvm and opened a gnome-terminal as root (you need to be root or use sudo, to make changes here).
  3. Completely unnecessarily, I backed-up the old symbolic link file, just in case. The easiest way is to use mv (by default mv doesn't follow sym-links), but if you'd prefer to make a copy of a symlink (rather than the object to which it points) you need to use the -P switch, e.g.
    cp -P java-6-sun java-6-sun_OLD.
  4. Made a copy of the jinfo file:
    cp .java-6-sun.jinfo .java-6-sun.jinfo_ORIGINAL_1.6.0.06
  5. Made java-6-sun symbolic link point to the new JDK directory:
    ln -s jdk1.6.0_10/ java-6-sun
And it does seem to work. NetBeans reports that it's using 6u10, and I haven't seen any empty dialogs yet! Better yet, NetBeans seems to start and run faster, too. (I haven't timed it - this may be placebo effect...)

Hope this may help out other folk using LinuxMint or Ubuntu, facing the same problem. Of course, remember that you can easily disable Compiz (set Visual Effects to None in the Appearances Preferences), and you can get some simple effects back using Gnome Compositing, available via the Mint Desktop tool in Control Center.

4 comments:

  1. This is great news!

    Thank you very much for your detailed tutorial. I faced the same problem some time ago, and I decided to disable compiz till this incompatibility is fixed.

    It's good that its fixed in 6u10. I will give it a try

    Keep up the good work!

    Christos

    ReplyDelete
  2. Hi,

    My name is Varun Nischal and I'm the NetBeans Community Docs Contribution Coordinator. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org/CommunityDocs).

    Would you be willing to contribute it? If you need any help or have any questions, please contact me at nvarun@netbeans.org

    I look forward to hearing from you.

    Thanks,
    Varun Nischal
    http://nb-community-docs.blogspot.com/
    --
    "You must do the things you think you cannot do."

    ReplyDelete
  3. Thanks for the post. I get the same problem with Oracle SQLDeveloper (also java based), Kubuntu 8.04 and Compiz.

    I suspected Java and Compiz weren't playing ball for some reason and this pretty much confirms my suspicions. I'll try it with a later version of Java.

    ReplyDelete
  4. WoW shares many wow gold of its features with previously launched games. Essentially, you battle with Cheapest wow gold monsters and traverse the countryside, by yourself or as a buy cheap wow gold team, find challenging tasks, and go on to higher Cheap Wow Gold levels as you gain skill and experience. In the course of your journey, you will be gaining new powers that are increased as your skill rating goes up. All the same, in terms of its features and quality, that is a ture stroy for this.WoW is far ahead of all other games of the genre the wow power leveling game undoubtedly is in a league of its own and cheapest wow gold playing it is another experience altogether.
    Even though WoW is a wow gold cheap rather complicated game, the controls and interface are done in buy warhammer gold such a way that you don't feel the complexity. A good feature of the game is that it buy wow items does not put off people with lengthy manuals. The instructions cannot be simpler and the pop up tips can help you start playing the game World Of Warcraft Gold immediately. If on the other hand, you need a detailed manual, the instructions are there for you to access. Buy wow gold in this site,good for you ,WoW Gold, BUY WOW GOLD.

    ReplyDelete