Repairing Sun’s WTK After a JDK Upgrade
Craig Setera — December 21, 2008 @ 5:32 pm — Miscellaneous
I have managed to get behind on the state of the Eclipse Mobile Tools for Java code. In an effort to catch up, I downloaded the latest code to my Ubuntu box and started up a runtime workbench. At that point, I needed to import my devices into the workspace and pointed to my Sun 2.5.2 Wireless Toolkit installation. To my surprise, it failed to be recognized. Given that I had fixed a similar problem prior to the MTJ 0.9.0 release, I was surprised to see a return of the problem.
Before digging too far into the MTJ code, I decided to see that the emulator was actually working correctly. I changed into the WTK emulator directory and attempted to run the emulator directly.
setera@ubuntu-laptop:~/software/wtk252/bin$ ./emulator ./emulator: 26: /usr/lib/jvm/java-1.5.0-sun/bin/java: not found
Ah Ha! My emulator installation is broken. What’s going on?
setera@ubuntu-laptop:~/software/wtk252/bin$ java -version java version "1.6.0_10" Java(TM) SE Runtime Environment (build 1.6.0_10-b33) Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
Sure enough, I remember recently updating my Java installation on this machine and deleting the older Java 5 installation. Of course, I had forgotten that the Sun WTK writes these files during installation. Edit the emulator file with a text editor and sure enough you can see that the installation path is hardcoded within the shell script file.
In fact, all of the shell scripts in the WTK bin folder have the incorrect Java installation folder.
setera@ubuntu-laptop:~/software/wtk252/bin$ grep "/usr/lib/jvm/java-1.5.0-sun/bin/" * defaultdevice:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ emulator:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ i18ntool:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ ktoolbar:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ mekeytool:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ prefs:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ siptool:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ utils:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/ wscompile:javapathtowtk=/usr/lib/jvm/java-1.5.0-sun/bin/
A bit of searching on my machine tells me that Java is linked into /usr/bin.
setera@ubuntu-laptop:~/software/wtk252/bin$ which java /usr/bin/java
The safest configuration is to point to the actual installation folder. Following a few links yields the installation path of /usr/lib/jvm/java-6-sun/jre/bin
setera@ubuntu-laptop:~/software/wtk252/bin$ ls -l /usr/bin/java lrwxrwxrwx 1 root root 22 2008-11-02 07:18 /usr/bin/java -> /etc/alternatives/java setera@ubuntu-laptop:~/software/wtk252/bin$ ls -l /etc/alternatives/java lrwxrwxrwx 1 root root 36 2008-11-02 07:18 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
Editing the shell scripts and replacing the incorrect Java installation path with the correct path corrects the WTK installation and allows it to be used within MTJ again.
setera@ubuntu-laptop:~/software/wtk252/bin$ ./emulator Syntax: emulator [arguments] <Application>
If you end up having trouble importing or otherwise running a Sun WTK emulator on Linux, you may want to try looking at your installation to see if you have a similar problem.