File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes class name collision among jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "class name collision among jar files" Watch "class name collision among jar files" New topic
Author

class name collision among jar files

chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
Hi,

I am working on eclipse. I have 2 jar files with the same name. One is the older version and one is the newer version. So,both these jar files have the classes with the same name but methods signatures differ. I want to use methods from both these jars ON THE SAME OBJECT. When I add both these libraries to the eclipse project as referenced libraries, the program is only accepting methods from the first jar file and it is showing errors when I use the methods from the second jar file. What can/should I do now? Both these jars have compiled classes in them.



Chandana.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

IMO that's a really bad idea, and it's rare it's necessary.

That said, you'll have to shadow one of the jars somehow--there are programs on the web that can do this for you in a variety of ways. On the very rare occasions I've had to do this I usually use something like jarjar to create a new jar of the library that has dependencies on the old jar. The new jar contains both the library and the old version of the jar.

If *your* code needs to use both versions then I'd recommend rewriting your code.
chandana nannapaneni
Ranch Hand

Joined: Dec 18, 2008
Posts: 39
Thanks David for the reply.

I am sorry.I didnot get you.Can you be more clear.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not really; that's about as simple as I can make it.

Wanting to use multiple versions of the same classes is a recipe for trouble and it should be avoided whenever possible--which is almost always.

When it's *not* avoidable, you can create a jar file that contains both its own code and a "shadowed" version of the library that's causing the conflict. One tool to do this is jarjar; there are others, and it's pretty easy to write your own (but I wouldn't bother, if I were you).

If *your* code, in other words, if *you* are writing code that depends on multiple versions of the same classes, then you should rewrite your code--it's simply not worth the pain, in my opinion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class name collision among jar files