Developing Java ME apps on Ubuntu

In Mobile development on November 30, 2009 by Matt Giuca Tagged:

I just spent two hours trying to build a Hello World for the Java ME (Micro Edition) platform. A fate I don’t wish you, gentle reader, to suffer, I humbly present this step-by-step guide to starting Java ME development on Ubuntu 9.10. I specifically target Ubuntu (or other Linuxes) because all the guides I could find online assumed Windows, which appears to have some different requirements (what happened to Write Once, Run Anywhere™?)

Firstly, I hate IDEs. I couldn’t get the command-line compilers (javac and the like) working — sure I could have if I spent another few hours fiddling. But since most of the advice online refers to NetBeans IDE, I used that.

OK, here we go.

Step 1: Install Debian packages (I always use Debian packages where possible).

sudo apt-get install openjdk-6-jdk netbeans

This installs the full Java 6 development kit, as well as the NetBeans IDE.

Now you will need to install the NetBeans Mobility plugin, which provides support for J2ME development, and the Sun Wireless Toolkit (WTK), which provides the actual libraries to compile against.

Step 2: Install the NetBeans Mobility plugin.

If you choose File -> New Project, you will find no way to create a J2ME project! You need to install the Mobility plugin.

Close that, and choose Tools -> Plugins. Under Available Plugins, select Mobility (Category: Java ME). Install that. Now under File -> New Project, you will find Java ME. Choose to create a Mobile Application.

Step 3: Install the Sun Wireless Toolkit.

Having chosen Mobile Application, you will be presented with a dialogue with a red error at the bottom: “No J2ME compatible platform is installed in the IDE. You need to have at least one J2ME compatible platform installed in the IDE.” So you’re still missing the actual library files required to compile J2ME apps.

So after much searching, I found what I think is the correct download (but there are lots of similar ones with different versions): Sun Java Wireless Toolkit 2.5.1 for CLDC. You should pick the Linux version, and download it (it’s called sun_java_wireless_toolkit-2_5_1-linux.bin).

Download it to your desktop, then run:

$ chmod +x sun_java_wireless_toolkit-2_5_1-linux.bin
$ ./sun_java_wireless_toolkit-2_5_1-linux.bin

Now this is really annoying in itself. You will be asked lots of silly questions:

  1. Hold down SPACE to skip the license agreement (I think this is just the GPL, so you shouldn’t even have to agree to it). Type “yes”.
  2. It will likely say “No suitable Java interpreter was detected”. Type “0” to “Specify a path to a Java interpreter directory.”
    • If you installed openjdk-6-jdk like I said above, it should be installed in /usr/lib/jvm/java-6-openjdk/bin/.
    • You might have many Java bin directories installed. To find one, type ‘which jar’. This might give you a symlink (such as /usr/bin/jar). Use ‘stat /usr/bin/jar’ to follow the symlinks until you find the real location, such as the one above.
  3. You are asked to enter a directory to install WTK. Just pick somewhere out of the way, probably in your home directory unless you want to share it with other users.

Step 4: Add the WTK platform to NetBeans.

Now that WTK is installed, we can fix the above issue in NetBeans.

In the New Mobile Application dialogue (heading should be Install Platform), click Install SDK/Platform/Emulator. (You can access this from the Tools -> Java Platforms menu also).

Click the Add Platform button, choose Java ME MIDP Platform Emulator, and then you will be asked to “choose a directory to search for platforms”. Choose the directory where you installed WTK. It should have a special icon. Now it should do some detection magic, and install a platform with a checked checkbox in the Add Java Platform window.

Click Next a few times, and you will see the Java Platform Manager screen with a J2ME folder, and the “Sun Java(TM) Wireless Toolkit 2.5.1 for CLDC” under it.

Now you can complete the wizard to create a mobile application with MIDP! It even has a checkbox to create a little “Hello World” app. Now to get the damn thing running …

Update: Hmm .. can’t seem to figure out how to get the emulator running, but compiling and transferring the .jar file to my phone works. (I had to change the setting from MIDP 2.1 to MIDP 2.0 to get it to work, YMMV.)


15 Responses to “Developing Java ME apps on Ubuntu”

  1. thanks,that was truly helpful

  2. Hey, thanks! You helped me a lot.
    Now I’ll try to help you… You said that installing .bin is annoying. I found a way to make it easier:

    Right-click on some bin file
    Options->Open with->Add->Own command and type
    gnome-terminal -e “sudo bash %f”

    now bin files can be “double-clicked”

  3. Just found out… the same can be done with NetBeans Installer (I used it because there’s no package for the last version)

    gnome-terminal -e “sudo sh %f”
    .sh extension

  4. Hi,

    thank you for very useful installation guide for Ubuntu & NetBeans IDE & JavaME!

    As I followed your guide, I manaed to get the emulator run without problems. Maybe Sun has updated their Linux package of the WTK?

  5. Very helpful. Thanks. I owe you a beer.

  6. Thanks for this got it working at last 🙂

  7. Thanks mate – got me up and running in no time. Really appreciate it.

  8. Thank you so much for this valuable information, it worked perfectly!!

  9. Thank U so mu dude i help me so much. it worked perfectly !!

  10. Thank you so much for this post. This post helps me. Greetings from Mexico.

  11. The license for the WTK is not the GPL, and it does not qualify as Free Software. I am looking for an acceptable alternative so that my Free MIDlets do not require a non-Free library to compile. Does anyone know of one? I hope the OpenJDK has the MIDP and CLDC implementations in it…

  12. Hello ,
    The download link that you provide doesn’t work anymore .
    Is there any other way to download the development kit ?
    And thanks in advance .

  13. This is really a very great help bro! God bless you?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: