Monday, July 06, 2009

Preparing 64-bit Ubuntu for J2ME Development

J2ME development on a 64-bit OS is unfortunately not as programmer friendly as it should be right now. Sun's Wireless Toolkit for CLDC currently only supports 32-bit development, so we're stuck trying to get 32-bit JDK up on a 64-bit Ubuntu.

The good news is there's a Ubuntu package to help us along the way; or at least part of the way. From Ubuntu's package archives, we'll need to install java-package, then proceed with installing the JDK which we'll need to download ourselves from Sun's website.

~$ sudo apt-get install java-package
~$ DEB_BUILD_GNU_TYPE=i486-linux-gnu DEB_BUILD_ARCH=i386 fakeroot make-jpkg
jdk-6u14-linux-i586.bin
~$ sudo dpkg -i sun-j2sdk1.6_1.6.0+update14_amd64.deb

At this point, I got an error from dpkg about missing a missing plugin file. Normally this can be ignored since there's no official Java plugin for 64-bit Linux yet, but in this case it will actually hamper any future package installations so I "fixed" it manually by creating an empty libjavaplugin.so and linking to i386 libjavaplugin_oji.so.

~$ sudo mkdir -p /usr/lib/j2sdk1.6-sun/jre/plugin/amd64/ns4
~$ sudo mkdir -p /usr/lib/j2sdk1.6-sun/jre/plugin/amd64/ns7
~$ sudo ln -s /usr/lib/j2sdk1.6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/j2sdk1.6-sun/jre/plugin/amd64/ns7/libjavaplugin_oji.so
~$ sudo touch /usr/lib/j2sdk1.6-sun/jre/plugin/amd64/ns4/libjavaplugin.so~$ sudo apt-get install -f

If you have more than one JVM installed then you'll need to run update-alternatives to set j2sdk1.6-sun as the default.

~$ sudo update-alternatives --config java

Next up would be to prepare Sun's Wireless Toolkit for CLDC (WTK). The current version is 3.0 but that seems to come bundled with J2ME 3.0 which means it's Windows-only (for now), so we'll be using 2.5.2 for our purposes.

Those who prefer using a IDE instead of a more minimal setup will want to install NetBeans IDE instead. The latest release includes JavaME support so you won't need to install WTK manually. NetBeans users will want to skip the rest of this post.

~$ sudo chmod +x sun_java_wireless_toolkit-2_5_2-linux.bin
~$ ./sun_java_wireless_toolkit-2_5_2-linux.bin

Follow the installer's instructions. I chose to install into a folder in my Home folder. I've never liked contaminating my OS with unofficial/unsupported software, so I try to avoid installing anything into the system as much as possible.

WTK runs perfectly fine wherever you place it, so there's no worries there. Afterwards, I simply write a simple script to launch the toolkit for me so I don't have to open up a terminal for it everytime I need it. Just fire up vim (or your favourite text editor) and type the following:

#!/bin/sh

~/WTK2.5.2/bin/ktoolbar

I saved it as 'ktoolbar' then made it executable, like so:

~$ sudo chmod +x ktoolbar

Double click to run it. Now you're ready to make some midlets. Nokia has a nice and short webinar that you can also download as a pdf for offline consumption. At the time of this writing, I've only just completed up to the sample first midlet myself and I find the webinar to be quite clear and easy to follow.

Note:

There was a bug that caused ktoolbar to not run. That bug has been fixed and ktoolbar should run normally.

Resources:

- 32-bit JDK on a 64-bit Ubuntu System
- Java SE Development Kit
- Sun Java Wireless Toolkit 2.5.2 for CLDC
- Java ME for Nokia Platforms E-learning

3 comments:

  1. Thank you for posting this.

    However, when I launch ktoolbar, I get the following message.
    Gtk-Message: Failed to load module "canberra-gtk-module": /usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so: wrong ELF class: ELFCLASS64

    It appears the WTK is referring a 64-bit version of libcanberra-gtk-module.so even though there is a 32-bit version of it (under /usr/lib32). It's actually causing problems when I try to launch a J2ME application through the Eclipse (EclipseME). Do you have any suggestion to resolve this problem?

    ReplyDelete
  2. I haven't encountered this myself, but a quick search turns up that this is a known issue with gtk+. ktoolbar isn't the only affected application.

    If there's updates for the distro you're using then you could try updating and see if that helps.

    ReplyDelete
  3. A bug causing ktoolbar to not run has since been fixed. Things should run as normal now.

    ReplyDelete