| Stephen de Vries ( @ 2006-01-14 17:38:00 |
| Entry tags: | midp netbeans mac os x mobility pack os |
MIDP Development with NetBeans on Mac OS X
Yes, you can do MIDP development under Mac OS X with NetBeans! NetBeans is a great IDE for Java development, it's just a pity that Sun hasn't released a Mobility Pack for Mac OS X.
But there are other MIDP device emulators, notably the excellent mpowerplayer which is a pure Java implementation and works beautifully on OS X. So all that's needed is to copy over a mobility pack (from linux or windows) and then configure it to use mpowerplayer, instead of the default WTK; here's how to do it:
- Download and install the NetBeans IDE for Mac OS X from NetBeans.org, in this example I used 5.0-RC1, and installed it in /Developer/Applications.
Note: The default font size of NetBeans on a 15 inch powerbook, makes the code look like it was written with a blunt crayon and also wastes valuable screen real-estate. If you'd like a smaller font you can add the following line:fontsize 11
to the startup command in the file:/Developer/Applications/NetBeans.app/Contents/Resources/NetBeans/bin/netbeans - Next, download and install mpowerplayer, I unpacked the archive in /usr/local/mpp-sdk. Also ensure that the preverifier tool has execute permissions, in this case:
chmod 755 /usr/local/mpp-sdk/osx/preverify/preverify - Download and install NetBeans and the mobility pack on a Linux or Windows system.
- In the NetBeans installation directory on the Windows/Linux system, copy the folder called "mobility7.2" to the /Developer/Applications/NetBeans.app/Con
tents/Resources/NetBeans folder on your Mac. - Because of what looks like a bug in NetBeans, I couldn't execute the debugger directly from NetBeans, so as a workaround created a shell script to act as a wrapper. So I created the folder
/usr/local/mpp-sdk/scriptsand/usr/local/mpp-sdk/scripts/temp, and then created the file /usr/local/mpp-sdk/scripts/nb-debug.sh with the following contents:
#!/bin/sh
rm -f /usr/local/mpp-sdk/scripts/temp/*
FILEBASE=`echo $1|sed s/\.jad//`
TRANS=$2
SERVER=$3
SUSPEND=$4
ADDRESS=$5
echo "FILEBASE= $FILEBASE.*">> /usr/local/mpp-sdk/scripts/log
cp -f $FILEBASE.* /usr/local/mpp-sdk/scripts/temp
java -Xdebug -Xrunjdwp:transport=$TRANS,server=$SERVER,suspend=$SUSPEND,address=$ADDRESS -jar /usr/local/mpp-sdk/player.jar /usr/local/mpp-sdk/scripts/temp/*.jad
Remember to give the script execute permissions. - Now we're ready to fire up NetBeans and configure the IDE. Under the Tools -> Java Platform Manager, you should see a section for J2ME (if you don't, then you probably copied the mobility7.2 folder to the wrong location). Choose Add Platform, and the choose Custom Java Micro Edition Platform Emulator, and fill in the following information:
Platform Home: /usr/local/mpp-sdkPlatform Name: MPowerPlayer(or whatever you'd like to call it)Device Name: MPP(or whatever you'd like to call it)Preverify Command: "{platformhome}{/}osx{/}preverify{/}preverify" {classpath|-classpath "{classpath}"} -d "{destdir}" "{srcdir}" Execution Command: java -jar {platformhome}{/}player.jar {jadurl}Debugger Command: {platformhome}{/}scripts{/}nb-debug.sh {jadfile} {debugtransport} {debugserver} {debugsuspend} {debugaddress}
Note: Make sure that you entered these values correctly, because it may not be possible to make individual changes later on without entering all the values again. Any edits to these values after this setup is completed, were ignored by NetBeans. I had to remove the mpowerplayer platform and then add it again. - Next, you should add the classes.jar file from:
/System/Library/Frameworks/JavaVM.framewto the Bootstrap libraries.ork/Versions/1.4.2/Classes
Note: You should also add a 1.4.2 JDK as a J2SE platform, if you only have a 1.5 JDK listed as a platform. - When starting a new MIDP project, you'll have to change the project properties to use the new MPowerPlayer platform instead of the default WTK (Thanks Rhys).
- All done! NetBeans should now be configured to build and debug J2ME projects!
Thanks to Lukas Hasik for this blog entry explaining most of the above procedure.
Debugger attached:
Flow design: