Tuesday, 12 December 2006

J2ME development on OS X

(This was originally written in October. Since then Netbeans have changed their download pages and made the procedure more or less impossible to follow. This is the corrected update.)

It’s nearly the end of 2006 and there still isn’t a packaged J2ME development environment for OS X. The stumbling block appears to be that the emulators include native code, and that the companies developing the emulators are unwilling to port them to another platform, or port them into 100% Java.

Since I don’t have a Windows box, and I can’t be bothered fighting Linux anymore, I tried various hacks to get this working under OS X (Mac Mini, Intel, OS X 10.4.8).

Massive thanks are due to Lukas Hasik and Florian Beer - see references at the end.

Grrr to whoever at NetBeans reorganised the product download pages and removed all the zip file versions of the CLDC mobility pack.

Overview

This uses pre-release builds for NetBeans 6.0 and the NetBeans Mobility Pack. I haven’t encountered any particular problems but it’s fair to say I’m not doing a lot of J2ME development.

The emulator is the popular Mpowerplayer SDK.

Process

1. Download the zip file for the CLDC Mobility Pack from here.

Note that currently you cannot select this file from the NetBeans download page! In fact you can't select any useful version of the CLDC pack from the NetBeans download page.

2. From the NetBeans 6.0 Q-Builds page, download the IDE build for 200609161800_1. Get the Mac OS X installation and un-tar it. You might want to rename the directory something like NBJ2ME.app, since this will include the J2ME development environment.

Change into this directory.

(I've tried using later builds of the IDE but they don't work with this build of the mobility pack.)

3. The mobility pack will have extracted to a directory called "mobility8". Move this directory to "Contents/Resources/NetBeans/mobility8".

Edit the file “Contents/Resources/NetBeans/etc/netbeans.clusters” and add “mobility8” on a new line at the end of the file.

4. Now we need to install the emulator. This also includes the CLDC and MIDP classes (which are not included in the Mobility pack. Go figure.) Download the Mpowerplayer SDK from here and unzip it (the location is not important). The latest version should be fine, I’m using Build 1185.

5. Start NetBeans and go to Tools->Java Platform Manager. Press Add Platform, select Custom Java Micro Edition Platform Emulator and select Next.

6. Set Platform Home to the path to the location you installed Mpowerplayer to. (This will probably end with mpp-sdk.) Platform Name and Device Name are not important, you could set them both to MPP.

7. Set Preverify Command to (Note: this goes all in one line):
"{platformhome}{/}osx{/}preverify{/}preverify" {classpath|-classpath "{classpath}"} -d "{destdir}" "{srcdir}"

8. Set Execution Command to (again one line):
java -jar {platformhome}{/}player.jar {jadurl}

9. Set Debugger Command to (you get the deal):
java -Xdebug -Xrunjdwp:transport={debugtransport},server={debugserver}, suspend={debugsuspend},address={debugaddress} -jar {platformhome}{/}player.jar {jadurl}

10. Press the Next button. All .jar and .zip files belonging to the Mpowerplayer SDK will be listed and if we don’t do anything, will be added to the NetBeans bootstrap class list. We need to remove some otherwise we will be unable to build applications. Remove the following files:

cldc.jar
midp.jar
xcode/template/xcodetemplate.zip
player.jar
protector.jar
tutorial/bin/FirstPowerMIDlet.jar

11. Press Finish.

That’s it! You should now be able to create a new project (category = Mobile, project = Mobile Application) build and run it.

References:
1. Zip distribution of mobility pack (Lukas Hasik)
2. J2ME Development on NetBeans 5.0 in Mac OS X (Florian Beer)

Feedback:
Send your comments to doug redclock net.

2 comments:

cricket said...

Hi, I wanted to follow your steps in making the mobility pack work for the MacOSX, but the oldest Q-Build version available for download in the netbeans website is already the m6 build, the one you are referring in your steps is the m3 build. Would you know how I can go about getting myself a copy of the m3 build?

Or is there a better way of getting mobility to work for Netbeans in MacOSX now? Any help would be greatly appreciated.

Thanks.

Neil said...

THANK YOU SO VERY VERY MUCH!
After hours spent following various tutorials for outdated versions and a whole load of Googling, I finally found your guide!

Words cannot express my gratitude!