Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

class name collision among jar files

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David for the reply.

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

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!