Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Contributor
Posts: 3
Registered: ‎11-10-2010
My Device: Not Specified

Tutorial: How embed 3rd Party jars into your Application.

[ Edited ]

Hi,

I have been looking for a while for a way to embed a 3rd party jar in my application's cod without the need to ship a separate cod file for the library. I did not see any tutorial on it, so I decided to post one (after spending many hours of trial and error).

 

There is a good post on how to convert 3rd party jar into cod:

http://supportforums.blackberry.com/t5/Java-Development/Tutorial-How-To-Use-3rd-Party-Libraries-in-y...

, but it may be preferable to package application in a single cod file.

 

The 3rd party jar in my situation was my own library, so I will show the way to compile library jar first:

1)      Compile the library using rapc

<rapc destdir=" myLibDir/out" output="myLib" srcdir="myLibDir" jdehome="${jde.home}">

          <jdp title="myLib" vendor="MyCompany" version="1.0.0.0" />

 </rapc>

Notice that I used “cldc” instead of “library”. This is based on information provided in this post: http://supportforums.blackberry.com/t5/Java-Development/MissingNativeError/td-p/184282

 

2)      Resulting jar is bloated with .cso, .cod, .csl. files, so the script below removes them. It also removes “MicroEdition-Profile: MIDP-2.0” line in the jar manifest file. It has to be removed, otherwise, you will get a cryptic run time error.

    <unzip src=" myLib.jar" dest=" myLib ">

    </unzip>

    <exec dir = "." executable = " rpl.exe" spawn="false">

        <arg value = "-x&quot;.MF&quot;"/>

        <arg value = "-R"/>

        <arg value = "&quot;MicroEdition-Profile: MIDP-2.0&quot;"/>

        <arg value = " "/>

        <arg value = "myLib"/>

    </exec>

    <zip destfile=" myLib.jar" >

       <zipfileset dir="myLib" excludes="*.cso *.cod *.csl"/>

    </zip>

    <delete dir="myLib”/>

 

You should have a preverified jar file at this point.

If the jar is indeed a 3rd party library without source code, you may need to run preverify (if it was not done):

JDE_HOME/bin/preverify -classpath "JDE_HOME/lib/net_rim_api.jar" "myLib.jar".

The tool will output preverified jar into the "output" directory.

 

Now you should be ready to use the library in your Eclipse project.

You will need to do 2 things:

1)      Go to Project Properties and select “Java Build Path”. Switch to Libraries and click “Add External JARS…”. Navigate to the jar and add it to the list of libraries. I have tried to use "User Libraries", but it did not work correctly - compiled, but did not export the jar into application cod.

 

2)      Now switch to “Order and Export” tab and check the library jar. It will force Eclipse to embed the jar into resulting application cod file.

This should be it.

 

Now as far as building application from ant, the trick is to use <src> element and add the jar. <import> does not embed the jar! Something similar to below:

<rapc destdir=" myAppDir/out" output="myApp" srcdir="myAppDir" jdehome="${jde.home}">

  <src>

      <fileset dir="myAppDir"/>

      <fileset file="myLib.jar"/>

  </src>

  <jdp title="MyApp" vendor="MyCompany" version="1.0.0.0" type="cldc" />

</rapc>

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Tutorial: How embed 3rd Party jars into your Application.

"Notice that I used “cldc” instead of “library”. The jar is only usable if compiled with “cldc”. 

 

What exactly do you mean by this?

New Contributor
Posts: 3
Registered: ‎11-10-2010
My Device: Not Specified

Re: Tutorial: How embed 3rd Party jars into your Application.

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Tutorial: How embed 3rd Party jars into your Application.

I think that only applies to compiling the library into the project (I have not seen that error and I've compiled in libraries before).

 

If it is installed as a separate cod, you should not have such issues.

Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Tutorial: How embed 3rd Party jars into your Application.

Hello, I am trying to include the jar files using Ant Tools. But the solution posted by you isn't working  with

<fileset file="Lib/xyz.jar">. Can you please let me know what might be wrong and any help would be greatly appreciable. Thanks in advance.