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

Reply
Developer
kchantp
Posts: 77
Registered: ‎11-20-2008
My Device: Not Specified
Accepted Solution

Including external jars into a compiled cod file w/ the Eclipse plugin

I am trying to include a jar into my application using the Eclipse plugin.  I have looked around the forums and so far I've gotten mixed messages.  On one hand, there's a KB referring to adding a jar into an application here:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Compi...

 

The originating thread (http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=6403) referred to the article but then MSohm's reply states that it's not possible in eclipse yet to include 3rd party jars into the application.  This was a few months ago and I was wondering...what is the authoritative answer?  

 

Personally, I've been able to link the jar into my application in Eclipse (make the jar its own project and have a project dependency on it) and have the simulator successfully recognize that both projects/modules are present.  However, once I create the cod file for my application and load it onto my handset (via javaloader command line method), the dependent project was not carried over.  It seems like the simulator just starts up both "projects" but doesn't really associate them in the cod file.

Developer
gibli
Posts: 44
Registered: ‎03-10-2009
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

I don't have an answer for you but have a workaround.

 

Basically you can continue to use eclipse and dependent projects for IDE development.

 

Then I create ant build files for my projects via http://bb-ant-tools.sourceforge.net/

 

and compile all the dependent cod files into the main ones.

 

Regards,

 

New Developer
subash
Posts: 45
Registered: ‎03-04-2009
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

@kchantp,

 

When you are loading the app ino your device, you must also load the jar file which is comiled by Eclipse. Generate .alx files for both - you application and the jar library . When compiling the code in Eclipse, make sure that the option "Activate For Blackberry" is selected for both the application and the jar library.  Using Desktop manager , load both the alx files to your device. Your applicaion should work now.

Developer
kchantp
Posts: 77
Registered: ‎11-20-2008
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

@gibli:  Thanks for the suggestion.  I've looked around and it seems like bb-ant-tools may have a work around.  I'll take a closer look.

 

@subash:  I'm actually trying to it place it all into one codfile because I'm trying to place the file on a web server to get it delivered OTA.  I'd rather not have to manage two different alx files and require both to be installed for my main application to work.

 

From what I hear, this feature is not available in the last release of the Eclipse plug-in. I'm wondering if RIM will fix this in the next release of the Eclipse plug-in.  Not being able to place jars into cod files is a huge disadvantage to developing with Eclipse (I've got other non-BlackBerry projects to work on, that's why I like a central IDE).  Until now, the BlackBerry Eclipse plug-in has been fantastic and creates all the necessary files without hassle (cod files, jad file, etc.)

 

 

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

What is the third party JAR file?  If it is a library, you can create a library project in Eclipse and build that into a library COD file.  Your application can then reference this library COD file.  This is fixed in the gold release (1.0.0.67) of the BlackBerry JDE Plug-in for Eclipse.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
kchantp
Posts: 77
Registered: ‎11-20-2008
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

Hi Mark,

 

This 3rd party jar is a Utility package that I'd like to use.  It's been built in-house so luckily, I could just take the source code and incorporate it into my project.  This, however, is not always the case since I may just have the class files in the jar (the jar wasn't built using a BlackBerry project, it is strictly just a bunch of classes that I'd like to import).  I am currently using the gold release (1.0.0.67) that you're referring to.

 

I've tried the following methods:

1) Created new BB project.  Set as Library project.   Under libraries, added the external jar (ExternalJar.jar).  In main project, went to the Java Build Path and added the Library project as a required project.  There are still build errors in the main project (Cannot pull in the external jar from the library project).

 

2) Created new BB project.  Set as Library project. Put in all the source code into the project.  In main project, went to the Java Build Patha dn added the Library project as a required project.  The main project compiles properly (recognizes the link between the two projects).  Works in the BB simulator (since both projects are active configs).  I then need to load both jad and cod files (I do doing these through a web server for OTA) onto the device before they work.  If I try to just download the main project, the jad file says that the Library project has not been installed.  So I need to install the library cod file onto the device first before I can download the main project's cod file.

 

The second seems to be the way that you are referring to.  The problem with that is the jad/cod file of the main project cannot be installed until the library's jad/cod file is installed.  Is there a way to make it just one jad file (a generated one instead of a manually created jad file) to bring both cod files in? 

 

Also the latter only works if I have the source code, but I can't seem to get it to work without the source code, just class files in an external jar.  Why can't an external jar be added as a library of the main project so that when the cod file is created, it is just added as part of the cod file? How do I get just an external jar to be part of a project?

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

The library JAR file needs to be added to the project itself in order to be built into a COD file.

 

You can install both the library COD file and application COD file at the same time.  You can use the updatejar command line tool to combine the two JAD files ino one.  This tool is included with the BlackBerry JDE and BlackBerry JDE Plug-in for Eclipse (in the bin directory).

 

In case you'd like to hand craft the JAD, have a look at the following links.  Juse ensure that you list the library file first so that it is installed before your application.

 

http://na.blackberry.com/eng/deliverables/5820/Wireless_pull_user-initiated_447306_11.jsp

 

http://na.blackberry.com/eng/deliverables/5820/Attributes_for_jad_files_513047_11.jsp

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
dpdragnev
Posts: 39
Registered: ‎04-30-2009
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

Mark,

 

I have tried both, using the UpdateJar.exe and also manually changing the JAD file to include the other COD file. Both methods fail with "907 invalid cod network error" message. I was not able to look at the links you provided, looks like they are not available anymore.

 

Here is my updated JAD file: KS2 is the cod file I am trying to load before the application is installed:

 

Manifest-Version: 1.0 RIM-COD-Module-Name: ShopAssistMobile RIM-COD-Module-Dependencies: net_rim_cldc,KS2 MIDlet-Jar-Size: 117115 MIDlet-1: ,, RIM-COD-Creation-Time: 1244608879 MIDlet-Jar-URL: ShopAssistMobile.jar RIM-COD-URL: KS2.cod RIM-Library-Flags: 2 RIM-COD-SHA1: eb d4 ef 1e 96 da 39 d7 79 f0 3f d1 91 7d 7a 78 5d 31 04 ad RIM-COD-Size: 34576 RIM-COD-URL: ShopAssistMobile.cod RIM-COD-SHA1: 2c 5e f2 9b 0a c0 24 b3 0b 69 6a ac 58 11 de 64 3c b5 73 f3 RIM-COD-Size: 48752 MicroEdition-Configuration: CLDC-1.1 MIDlet-Version: 1.0 MIDlet-Name: ShopAssistMobile MIDlet-Vendor: Dragnev Software Solutions LLC MicroEdition-Profile: MIDP-2.0 RIM-MIDlet-Flags-1: 0

 

On the server, I have ShopAssistMobile.cod, ShopAssistMobile.jad, ShopAssistMobile.jar, KS2.jar, KS2.jad, and KS2.cod available in the same directory from which the user will download them.

 

If I install KS2.jad first and then ShopAssistMobile.jad (the original, without the 4 lines that reference KS2, the bolded text above) everything loads correctly, so I know the individual COD files are working without errors. 

 

I am developing using Eclipse (4.5) and am trying to upload to BlackBerry 8300 Simulator.

 

Thank you for your help,

 

Daniel

Developer
dpdragnev
Posts: 39
Registered: ‎04-30-2009
My Device: Not Specified

Re: Including external jars into a compiled cod file w/ the Eclipse plugin

[ Edited ]

To answer my own question: the mistake I was making was that I was not specifying the COD files in the form RIM-COD-URL-#. After rewriting the JAD file accordingly, everything worked well.  Here is a quick example provided by Eric Giguere.

 

MIDlet-Version: 1.0.0

MIDlet-Name: My Silly App

MIDlet-Description: Wish it would do something
MIDlet-Vendor: RIM Should Buy Us For Big Bucks, Inc.

RIM-COD-URL-1: library1.cod
RIM-COD-Size-1: 15088
RIM-COD-URL-2: library2.cod
RIM-COD-Size-2: 7963

RIM-COD-URL-3: sillyapp.cod
RIM-COD-Size-3: 41923

 

Hope that helps.

 

Daniel D.

Message Edited by dpdragnev on 06-10-2009 11:59 PM
New Developer
New Developer
rzr
Posts: 151
Registered: ‎01-05-2010
My Device: dev alpha c (bb10)

statically linking jar library into a single .cod appplication ?

Cant the lib be statically linked into a single .cod ?

 

1st I imported an external jar in the build panel, the application compiled fine

Exporting the lib does not seems to have effect (last panel in build option)

So I added the *.jar as an external source into my application project...

but it seems to cause trouble at compilation, it complains that code is not invoqued and on execution an exception is thrown : "java.lang.NoClassDefFoundError" ...

 

Note that I managed to make it working by installing 2 cod's ...