Stephen de Vries ([info]stephendv) wrote,
@ 2006-01-14 17:38:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
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:


  1. 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



  2. 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

  3. Download and install NetBeans and the mobility pack on a Linux or Windows system.

  4. In the NetBeans installation directory on the Windows/Linux system, copy the folder called "mobility7.2" to the /Developer/Applications/NetBeans.app/Contents/Resources/NetBeans folder on your Mac.

  5. 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/scripts and /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.

  6. 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-sdk
    Platform 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.


  7. Next, you should add the classes.jar file from: /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes to the Bootstrap libraries.
    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.

  8. 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).

  9. 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:



(Post a new comment)

Doh!
(Anonymous)
2006-03-27 11:34 pm UTC (link)
Remember to set the emulator platform to "MPowerPlayer in the project properties. I didn't and I was scratching my head for a while. If you don't it uses the WTK platform my default and tries look for preverify in the wtk22_win directory (if you used this version) and obviously fails. My Mac returned the error "/Users/rhyscampbell/.netbeans/5.0/emulators/wtk22_win/emulator/wtk22/bin/preverify not found"

Rhys

(Reply to this) (Thread)

Re: Doh!
[info]stephendv
2006-03-28 01:52 am UTC (link)
Thanks! Updated the entry to reflect this.

(Reply to this) (Parent)

Re: Doh!
(Anonymous)
2007-08-23 03:37 pm UTC (link)
hi Stephen,

I tried it and i got everything to work. Thanks for your wonderful tip.

However, when the emulator runs, i got this warning in the console

"2007-08-23 16:19:57.510 java[404] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x10403, name = 'java.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2007-08-23 16:19:57.512 java[404] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)"

Do you know why? Have you encountered the same error?

TIA

(Reply to this) (Parent)(Thread)

Re: Doh!
[info]stephendv
2007-08-23 03:48 pm UTC (link)
Yep, see it sometimes with other Java applications on OS X. But the apps usually work just fine. (No idea why it happens though...)

(Reply to this) (Parent)

ZIP distribution of Mobility Pack
(Anonymous)
2006-09-17 01:51 pm UTC (link)
That's good information for Mac users. The builds of Mobility Pack are provided like OS independent zip. That means that you don't have to install Mobility Pack on Win/Linux first. You can skip the steps 3,4. Please remember that this zip distribution have to be used with NB 6.0


http://www.netbeans.info/downloads/download.php?a=n&p=1&rv=6.0&bt=4&step=2 (http://www.netbeans.info/downloads/download.php?a=n&p=1&rv=6.0&bt=4&step=2)


http://blogs.sun.com/lukas/entry/zip_distribution_of_mobility_pack (http://blogs.sun.com/lukas/entry/zip_distribution_of_mobility_pack)

(Reply to this) (Thread)

Re: ZIP distribution of Mobility Pack
(Anonymous)
2007-07-13 11:58 am UTC (link)
To make the Mobile platform visible in the IDE on NetBeans 5.5.1 I had to edit the file

{/Developer/Applications}/NetBeans.app/Contents/Resources/NetBeans/etc/netbeans.clusters

to add "mobility7.3" (without quotes) to the Platform section.
After saving the file and restarting NetBeans, I could finally see "Mobile" as an option for a new project and in the list oof Platforms inside the Tools . Java Platform Manager.

(Suggested at http://blogs.sun.com/lukas/entry/zip_distribution_of_mobility_pack)

(Reply to this) (Parent)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…