Thursday, January 21, 2010

How to add a J2ME 3rd party library into your NetBeans project

Scenario
You need to port our J2ME application to a specific platform, either Nokia, Samsung or LG, etc. You have to use OEM's specific API to implement a feature, but that special API is not included J2ME standard library, nor included in the OEM's J2ME SDK. You got an ZIP or jar file of the API library, but mostly it they are just stub classes, the only real implementations are inside the actual devices. What you need to do is adding the library in your project class path, but without including them into the J2ME jar file.

Solution
In NetBeans IDE, You can add the libray of zip/jar file in your J2ME project without including in the packaged jar file. Here are the steps:
  1. Select your project, right click mouse, choose "Properties"
  2. Select Build - Libraries & Resources, click button "Add Jar/Zip ...", then select the libray file you want to add, press "Open"
  3. You will see the library file is included the file/folder list, pleases make sure uncheck the "Package" checkbox, this is the most important step, it will tell IDE don't include this jar/zip file into your J2ME jar file, or IDE will not build successfully, because it can not find dependencies packages for the libraries. The screen shot is attached at the end of this article.
  4. Select OK, and build your J2ME application 

4 comments:

  1. Hello & M working with J2ME Application Development and Thanks for this article. It is very useful to all.

    ReplyDelete
  2. My final year project was using Image processing on JavaME. felt a bit hard due to limited library. but will try my best. thanks for this good guide.

    ReplyDelete
  3. Before this guide my compiler was giving this error:NoClassDefFound:..
    But after a simple unchecked of the package checkbox on the imported jar, the problem was fixed.I spent 3 days looking for how to fix this issue and finally i got it here. Thx again!!!

    D

    ReplyDelete
  4. Dear Mr. Zhang

    After applying your advice my project got finally build.
    Can you please elaborate a bit more why including zip library into the package prevent succesfull build?

    ReplyDelete