J2ME Development on NetBeans 5.0 in Mac OS X

For a long time Mac OS X was the one platform left out when it comes to developing MIDlets. There where soultions from SUN for Windows, Linux & obviously Solaris. There was no official build for the amazing NetBeans Mobility Pack for the Mac … well, there still isn’t one but I looked around a bit in the gathered knowledge of mankind which is the WWW and found the blog of Lukas Hasik. He has a fairly well written documentation of how to achieve a working development environment on Mac OS X.

In this post I’d like to summarize the nessecary steps as well as make a few annotations where I ran into difficulties while following the described steps.

  1. Obviously you need to have the NetBeans IDE 5.0 installed (which I already had)
  2. Next you need the Mobility Pack, which I extracted from a Linux install of the NetBeans IDE 5.0 and Mobility Pack. For ease of use I provide the files for you to download here.
    Unpack the file and go on to the next step.
  3. Show Package ContentsFind the NetBeans application in your Applications folder and ctrl + click on it (or press the right mouse button). Choose “Show Package Contents” in the context menu.
    Another Finder Window will open.
  4. In the new Finder Window navigate to Contents -> Resources -> NetBeans and copy the extracted Mobility Pack folder (named “mobility7.2“) there. Now you should already be able to choose “Mobile Application” in the NetBeans IDE when opening a new project.
    The only remaining problem ist that we don’t have a suitable emulator … yet!
  5. Mpowerplayer LogoThe only J2ME emulator that runs natively on Mac OS X I know of is Mpowerplayer SDK which you can download here.
    Installing Mpowerplayer is a simple matter of unpacking and moving it to the desired location. In my case I moved it to /Users/flo/Java where I keep all Java development related stuff.
  6. Next thing to do is to make the preverifier runable. Open Terminal.app (in /Applications/Utilities) an navigate to {mpp_install}/osx/preverify/ (in my case cd /Users/flo/Java/mpp-sdk/osx/preverify) and run the following command:
    chmod +x preverify
  7. Now we need to integrate the Mpowerplayer into our IDE. Open NetBeans got to Tools -> Java Platform Manager and press Add Platform, select Custom Java Micro Edition Platform Emulator and click Next.
  8. Set Platform Home to the path you installed Mpowerplayer to. Platform Name and Device Name aren’t important, just set it to something you recognize. I set mine to “Mpowerplayer” and “mpp”.
  9. Set Preverify Command to (Note: this goes all in one line):
    "{platformhome}{/}osx{/}preverify{/}preverify" {classpath|-classpath "{classpath}"} -d "{destdir}" "{srcdir}"
  10. Set Execution Command to (again one line):
    java -jar {platformhome}{/}player.jar {jadurl}
    (Note: I substituted jadfile with jadurl as recommended in the Mpowerplayer development forums, to be able to set breakpoints properly)
  11. Set Debugger Command to (you get the deal):
    java -Xdebug -Xrunjdwp:transport={debugtransport},server={debugserver},
    suspend={debugsuspend},address={debugaddress} -jar {platformhome}{/}player.jar {jadurl}

    again changed to jadurl from the original jadfile
  12. Press the Next button.
  13. In the next screen you need to add classes.jar from your Java Framework. Click on Add, navigate to System/Library/Frameworks/JavaVM.framework/Classes/ and choose classes.jar from there.
  14. If you want to develop for MIDP2.0 & CLDC1.0 you have to add the appropriate jars as well, as they are not automatically added. cldcapi10.jar and midpapi20.jar are located in the Mobility Pack folder you downloaded earlier. To make things easy you can also download them here. Extract the archive and move the files for instance into your mpp-sdk folder. Afterwards return to NetBeans and add them to the Bootstrap Libraries.
    Now press Finish
  15. Choose PlatformIn the future your new Platform will be selectable whenever you choose “Mobile Application” when starting a new project.

That’s about it, I hope I didn’t forget anything. If so, please correct me in the comments. Thanks again to Lukas Hasik for researching and writing his howto thus enabling us Mac users to develop for mobile platforms without being forced to leave the comfort of our beloved OS πŸ™‚

27 comments

  1. hi, florian.
    thanx for this tutorial, i got it from rui’s site, the.taoofmac.com.
    excellent resource, although I figured out how to do the same using eclipse and eclipseME.
    it’s been a painful process, which eventually led me to move to Windows for just j2me development (eclipse ain’t that smooth on mac).
    I’ll definitely try this and see if I can get better results using NetBeans.
    thank you for supporting the mac community on this.

    ciao.ubi

  2. Hi Florian,

    Thanks for the summary here, this looks really promising! I seem to have all the bits I need, but something goes wrong when I try to build, the preverifying step craps out as follows:

    Preverifying 3 file(s) into /Users/jnutting/play/FirstMidpGame_mark2/build/preverified directory.
    /Users/jnutting/play/FirstMidpGame_mark2/
    nbproject/build-impl.xml:269: java.io.IOException: ???/Users/jnutting/Library/mpp-sdk/osx/preverify/preverify???: not found
    BUILD FAILED (total time: 0 seconds)

    I’ve checked and double-checked the path to the preverify command (and yes, it is executable, I can run it manually etc). I’ve even moved the mpp-sdk location to a completely different location, recreated the config in NetBeans, and I still keep getting this error! I’ve also tried messing with the double-quotes in the config strings (since they seem to be turned into “smart quotes” when I copy from your page), but that made no difference either.

    Any ideas?

  3. Problem solved…. it was indeed the “smart quotes” that came along in the copy/paste. This was exacerbated by the fact that even though NetBeans lets you edit the Preverify Command string in the Java Platform Manager window, it doesn’t actually save the changes you make there! After I realized that, I deleted and recreated the mpowerplayer platform again, and now it compiles fine.

    (To save others from this error, you may want to modify the source of this page a bit, changing the #8220 and #8221 elements to quot on the line in question so that it can be copy/pasted correctly)

    Thanks again for the excellent step-by-step!

  4. @Lukas
    I voted πŸ˜‰ (I’ll spread the word so others do it as well)
    I think you should definitely start thinking about OS X as supported platform in the future. At least at my university there seems to be a drift to switch to OS X and J2ME development is part of our education. So at least in Austria there will be a couple of J2ME developers in the coming years πŸ˜‰

    @Jack
    Thanks for the feedback!
    I modified the source as you suggested, hopefully it copies right now (got no time to test it at the moment).

  5. Hi,

    thanks for the HOWTO.

    Just wanted to point out that the quotes problem for the Preverify Command in step 9 above still exists.

    Also, trivially, the path in step 13 is wrong. It should be /System/Library/Frameworks/JavaVM.framework/Classes/

    And finally, in step 14, cldcapi10.jar and midpapi20.jar were NOT in the Mobility pack downloaded in step 2. (???) (but were in the tarfile linked in step 14).

    Thanks again, and OF COURSE Mac OS X should be a supported platform! πŸ™‚

  6. Sorry, I also wanted to ask:

    Are there any files that could be added to the Sources and Javadoc fields in the next panel?

  7. Thank you for your feedback Colin!

    I corrected the error in step 13.

    The quotes in step 9 are still an issue I know, but this blog software somehow doesn’t want me to change it. I had several issues with code listings in the past, so if anybody has some suggestions to improve code listings in wordpress just let me know!

    The cldcapi10.jar and midpapi20.jar ARE in the Mobility Pack, although somewhat hidden. That’s why I offered the files on my server for ease of use.
    They are in mobility7.2/emulators/wtk22_linux.zip which you have to decompress and there you’ll find them in wtk22_linux/emulator/wtk22/lib/. So now you see why my way was much easier for this HowTo πŸ˜‰

    As for your second question: I don’t exactly know which files you want to put in there. Could you elaborate on that?

  8. OK, thought the APIs might be hidden πŸ™‚

    As to Sources and Javadoc – I don’t know. That’s the question. I assume this is javadoc etc to enable code completion and hints etc (in the editor) when using MIDP and CLDC ?

  9. Hi, im asleep for three days trying to put my brand new mac mini to work the same way my G4 does.

    Well, all mi midlets refuse to preverify, after giving up with xcode and mpowerplayer i try your tutorial, well, mi preverify still fails.

    If i change my jvm to 1.4.2 the preverify doesnΒ΄t fail, BUT the midlets didn’t work on phone but it does in emulator.

    The almost famous error is :

    Error preverifying class java.lang.Class
    VERIFIER ERROR java/lang/Class.newInstance0()Ljava/lang/Object;:
    Illegal type in constant pool
    /Users/eduardo/MobileApplication/nbproject/build-impl.xml:269: Preverification failed with error code 1.
    BUILD FAILED (total time: 3 seconds)

    Anyone can help me ?

    ppppleaseeee …..

  10. I’ve got the “Preverification failed with error code 1. error as well”. It would be great if someone would know how to fix it. Otherwise, thanks for the great tutorial!

    Cheers, Filip

  11. Hello!
    I’m Japanese Mac hobbyist.
    I made a Japanese tutorial by referring to this blog.

    Thank you very much. ALL

    And, I will make a Mobile Application .

  12. The preverifier error occurs if you’re using Java 1.5. I used the 1.4.2 version (stored in/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/) and the preverifier seems to work.

  13. Hy,

    I finally got the NetBeans helloWorld working on my (french) iBook with NetBeans (and on my se w810)!

    I had to make the 2 changes precedently mentioned :
    ??????smart quotes??? to standard quotes on step 9
    ???System/Library/Frameworks/JavaVM.framework/Classes/ to /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes on step 13

    thank you so much for making this so clear!

    by the way, I still have a non fatal error (but, hey, it works!) :

    CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x10403, name = ‘java.ServiceProvider’
    See /usr/include/servers/bootstrap_defs.h for the error codes.

    java[978] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)

    I’ve looked at the bootstrap_defs.h file but that doesn’t talk much to me…

    Thanks again, and sure I’ve voted the issue!

  14. Thank your very much for your information, this is really useful to develop J2ME stuff on Mac OS X.

  15. I’ve been trying to get this installed under Netbeans 5.5, and it will not recognize the mpowerplayer as a platform. In 5.5, you are no longer allowed to manually enter the platform home. Instead, you have to browse to it and select it. In my version, there is no way to select the mpp-sdk folder as a platform folder. Did I miss something? I changed the permissions to allow the preverify to execute, and have tested this in the terminal.

  16. @Ryan:
    Since my work doesn’t require J2ME at the moment I haven’t updated to Netbeans 5.5 yet. So I can’t really figure out what the problem is there. I’d be glad if anyone could offer an update to this HowTo for the most recent Netbeans version.

  17. Yeah … got the same problem here. Netbeans 5.5 doesn’t recognize the mobility pack …

    Any ideas?

  18. I’m using the modified instructions here to get the mobility pack working in NB6 M7.

    I still get the preverify error:
    Preverifying 1 file(s) into /Users/adrian/Projects/NB6/MobileApplication1/build/preverified directory.
    Error preverifying class java.lang.Class
    VERIFIER ERROR java/lang/Class.newInstance0()Ljava/lang/Object;:
    Illegal type in constant pool
    /Users/adrian/Projects/NB6/MobileApplication1/nbproject/build-impl.xml:416: Preverification failed with error code 1.

    I’ve added the 1.4.2 version of classes.jar where necessary.

    I’ve even wrapped the preverify script with:
    #!/bin/sh
    export PATH=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/bin/:$PATH
    /Users/adrian/opt/java/mpp-sdk/osx/preverify/preverify $*

    I know this is a long thread now, but any ideas?
    Thx
    Adrian

  19. Thank you to all of you for the valuable Tips. I also got it working under Apples xCode mPowerPlayer even comes with a MIDP Code Template for xCode. The whole build process works fine via an ant script.

    The most important step is to call everything with the java 1.4.2 compiler. javac version 1.5 DOES NOT WORK for J2ME Development.

  20. I have got it working on Mac with XCode and MPowerPlayer.Compiles and and runs good on Emulator. But when I transfer the .jar to the actual device I get
    “java/lang/ClassFormatError: Bad version information” error message.

    I have specified the required attributes(-1,Name,Vendor,Version,Configuration,Profile) in the manifest.

    Any idea folks ? Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.