Monday 17 January 2011

External JAR problems on BlackBerry projects under Eclipse


I've been recently trying to parse some external XML's and for this I wanted to user the KXML2 library. But I came across a pretty nasty problem.

To be able to use this library you obviously need to add the jar file on your project. Everything ok until BlackBerry signals that it couldn't find the jar file specified. I wasn't the only one with this problem (see http://www.thinkingblackberry.com/archives/204) so it wasn't something I did wrong.

Anyway, there's a simple solution for this shortcoming. Here are the steps:

1. Download the jar file

2. Preverify the .jar file

This can be done from the command line. Before this, be sure you have java set in your environment variables (in my case “C:\Program Files\Java\jdk1.6.0_20\bin”). Now, copy your .jar file in JDE_HOME/bin and run the following command:

preverify.exe -classpath ..\lib\net_rim_api.jar your_jar_file_name.jar

Where JDE_HOME is the BB JDE home directory or the component pack home directory. The “preverify” command will generate the file in the “output” folder in JDE_HOME/bin.

3. Add the .jar to your project

Create a lib folder in your project, copy the preverified .jar file in there. Right-click on your project, go to “Properties” → “Java Build Path” → “Libraries” tab → “Add JARs”, select the preverified .jar file that you've just copied in the lib folder, click and “OK”. Now, while in “Properties” window, go to “Order and Export” tab and check the newly added .jar. Click “OK” and you should be done.

No comments:

Post a Comment