If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
New Developer
almiki
Posts: 19
Registered: ‎06-19-2009
My Device: Not Specified

'Duplicate definition' error when building a library that exports a .jar

The following situation is causing a "Duplicate definition for class 'com.foo.MyClass'" error:

 

I have a number of .jar files built with the JDK javac tool (no Blackberry tools involved). I have manually combined those jar files into a single file called mylib.jar. One of the classes is called 'com.foo.MyClass' (not the real name of course).

 

In my Eclipse workspace, I have a project called MyLibWrapper, which is a library project which simply has mylib.jar on its class path, which is checked under "Order and Export". The goal is to generate a .cod file with the contents of mylib.jar.

 

There is a second project called MyApp. When I add the MyLibWrapper project to its class path (i.e. the "Projects" tab of "Java Build Path" in the project properties), I get the aforementioned error when I package the application (MyLibWrapper seems to package fine). However, if I instead build and package MyApp with MyLibWrapper.jar on the class path (i.e. the "Libraries" tab), everything works great--it builds, and runs perfectly fine in the simulator.

 

This last part makes me pretty sure that I have built mylib.jar correctly. I don't see any evidence in either mylib.jar or MyLibWrapper.jar that MyClass is defined multiple times. I've also made sure that SampleApp is not pulling in anything other than MyLibWrapper and the RIM API jar.

 

Any ideas? Am I missing something? It seems like it could be a bug in the Blackberry JDE. I'm using the 1.3.0 plugin on Eclipse 3.6.1, and compiling with the 4.5.0.28 SDK.

Please use plain text.
Developer
simon_hain
Posts: 15,908
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: 'Duplicate definition' error when building a library that exports a .jar

do you have persistant classes in your library? this is not supported on blackberry.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
almiki
Posts: 19
Registered: ‎06-19-2009
My Device: Not Specified

Re: 'Duplicate definition' error when building a library that exports a .jar

I'm not completely sure what you mean by persistent classes, but I'm pretty sure I don't have any. I'm only using the RIM API via net_rim_api.jar, and nothing implements Persistable.

 

I've also tested with one of the original libraries prior to repackaging into mylib.jar with the same results. And I neglected to mention that I'm running preverify.exe on the jar.

Please use plain text.
Contributor
azoc
Posts: 35
Registered: ‎09-15-2011
My Device: Torch 9800, Tour 9630
My Carrier: VZW

Re: 'Duplicate definition' error when building a library that exports a .jar

Same problem here. My application requires a library project that exports a jar. Packaging fails every time with 'Duplicate definition' for the first class in the jar. Anyone ever figure this out?

 

My rapc output looks like this:

C:\Blackberry\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components\bin\rapc.exe

-convertpng -quiet codename=deliverables\Standard\5.0.0\myApp deliverables\Standard\5.0.0\myApp.rapc
-sourceroot= C:\workspace\myApp\src; C:\workspace\myApp\res

-import=
C:\Blackberry\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components\lib\net_rim_api.jar; C:\workspace\myLibrary\deliverables\Standard\5.0.0\myLibrary.jar C:\workspace\myLibrary\jar\thirdParty.jar C:\workspace\myApp\bin

 

Please use plain text.
Developer
superdirt
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: 'Duplicate definition' error when building a library that exports a .jar

When I got this error, it was because I wasn't setting up my dependencies correctly in the JDE. I was using someone else's JAR and was trying to add it as a dependency but I missed a step somewhere in the process. When I loaded it in properly, it worked like a charm. I was doing something different than what you are trying to do but I just thought I'd share this in case it gave you an insight for your purposes. Perhaps the problem is related to how you set up your project?

Scott

Please use plain text.
Contributor
azoc
Posts: 35
Registered: ‎09-15-2011
My Device: Torch 9800, Tour 9630
My Carrier: VZW

Re: 'Duplicate definition' error when building a library that exports a .jar

Do you happen to remember the steps you took? Everything checks out -- my library project is set to "Library" in the app descriptor xml and my application project is requiring it in Project Properties > Build Path > Projects.
Please use plain text.
Developer
superdirt
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: 'Duplicate definition' error when building a library that exports a .jar

Well I believe I was trying to achieve something different than what you are. I was importing a JAR into my workspace as a library, and you are exporting a JAR.

 

These are the steps to import a JAR:

 

http://supportforums.blackberry.com/t5/Java-Development/Compile-a-jar-file-into-a-BlackBerry-Library...

 

Scott

 

Please use plain text.
Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: 'Duplicate definition' error when building a library that exports a .jar

You can try following notion instead of importing classes into your class:

 

pkg.classname variable=new pkg.classname();

 

 

Please use plain text.
Developer
pbrebs
Posts: 40
Registered: ‎09-08-2011
My Device: 8900
My Carrier: AIS

Re: 'Duplicate definition' error when building a library that exports a .jar

With duplicate definition, make sure that the library project isn't also specified under "imported jar files" ("Properties" menu, then "Build" tab in JDE).
Please use plain text.