Set up a Java ME development environment on Mac OS X
Recently I decided to give Java ME a try. As I have a project created by other developers with NetBeans Mobility Pack, I thought I might just use the same IDE on Mac.
(Click to enlarge)
Installing NetBeans
I downloaded NetBeans 6.1 from http://download.netbeans.org/netbeans/6.1/final/. There’s no ready-built mobility pack for Mac, so I downloaded the Java SE version (coz I won’t use other features anyway, for those I use Eclipse). The installation is easy, no configurations needed. Right after I launched the program, there’re already several updates, so I just let it updated itself.
Installing Mobility Plugins and Mpowerplayer
Go to “Tools / Plugins“, select “Available Plugins” tab, find those two plugins - “Visual Mobility Designer” and “Mobility“, install them (and update them). Restart NetBeans.
Mpowerplayer is currently the only working MIDP emulator on Mac. Download it for free at http://mpowerplayer.com/?cat=6 . Extract Mpowerplayer SDK to any place you like. e.g. /Developer/mpp-sdk .
Go to “Tools / Java Platforms“, click “Add Platform..“. In the wizard select “Java ME MIDP Platform Emulator” and in the next screen choose the folder you extracted MPP SDK to. I use /Developer/mpp-sdk here. The wizard should find the platform automatically, then “Next” and that finishes this part.
(Optional) Replacing files (solves “String.equalsIgnoreCase” problem)
Now you should be ready to develop MIDP applications with NetBeans and Mpowerplayer. However, if you try to use certain methods in your application, say “String.equalsIgnoreCase”, you’ll get a “cannot find symbol” error (even if you’re using CLDC 1.1 profile, which should include this method).
A simple workaround is “toLowerCase().equals()“. However if you’re working with exisiting code (like in my case, someone created with WTK), you’ll find more missing classes and methods which have no simple workarounds.
So I decided to compile my code against Sun’s libraries. Configuring classpaths can be tricky so I just replaced the files. Here’s what I did:
- Download Sun Java Wireless Toolkit 2.5.2 . Remember to download the Linux version !
- Extract the package with unzip in a terminal, simply “unzip <the file name>” (Don’t do it in Finder, it simply doesn’t work). e.g.
sudo mkdir /Developer/sun_wtk cp ./sun_java_wireless_toolkit-2_5_2-linux.bin /Developer/sun_wtk/ cd /Developer/sun_wtk unzip sun_java_wireless_toolkit-2_5_2-linux.bin
- Now check the files you just extracted, copy all those 5 jars under “lib” directory to <mppsdk>/stubs/ and replace the ones that come with Mpowerplayer (make backup first). e.g.
cp lib/cldcapi10.jar /Developer/mpp-sdk/stubs/cldc-1.0.jar cp lib/cldcapi11.jar /Developer/mpp-sdk/stubs/cldc-1.1.jar cp lib/midpapi10.jar /Developer/mpp-sdk/stubs/midp-1.0.jar cp lib/midpapi20.jar /Developer/mpp-sdk/stubs/midp-2.0.jar cp lib/mmapi.jar /Developer/mpp-sdk/
- Now you should be able to use the same APIs as you would use with WTK. Do not delete the WTK directory, there’re still many useful libraries (e.g. WMA - the javax.wireless.messaging package) and demo applications.
Some Notes
- When opening projects created with older versions of Mobility Pack, NetBeans will ask you to convert the file format (basically changes on getter/setter to meet Java conventions). Do NOT trust the conversion, keep a copy of the original files, you’ll have to fix small errors like missing imports here and there in the new file
- The Visual Mobility Designer is really cool but don’t overuse it. As the diagrams aren’t generated from source code directly, but stored in separated files, NetBeans won’t allow you to edit much part of the generated code, and sometimes it just gets in the way. So still use handcraft code when possible (I only use the designer for UI and layout)
- If you compile your application against WTK libraries, you’ll have to consider license issues when publishing it.
- You should still test your applications on emulators from official SDKs and probably on actual devices. For example I wrote a very simple Hello world application and it runs well on Mpowerplayer, but simply doesn’t work on my Sony Ericsson K770i.

