Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Two Ja file having the same class file but different implementation.How to use both jar file?  RSS feed

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two jar contains same class(HttpTransport.class) under the same package name but having different implementation, How to solve the problem?

I am using two jar files : 1) google-api-client-1.4.1-beta.jar 2) gdata-2.2.1-alpha-client-http.jar

Both the jar files contains HttpTransport.class but having the different implementaion. But the package name for both are the same i.e.
But It creates the problem to use the class of the second jar file. I Need both the jar file so i can not remove any jar file from my project. Can anyone guide me how to solve this problem without delete any jar file.

Java Cowboy
Posts: 16084
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no simple solution for this problem.

Java's mechanism for finding classes is very simple. Everything that is in the classpath (directories and JAR files) is put into a list, and when Java looks for a class, it just takes the first one that it can find in the list. There is nothing to handle the problem of having multiple classes that have the same name and that are in the same package.

There might be a way to do this with a custom ClassLoader, but it will not be easy. Another solution is to use a module system such as OSGi, which allows you to have different parts of your application as OSGi bundles; each bundle can have its own dependencies on different versions of the same library.

To fix this problem, I would first investigate if it is absolutely necessary to have google-api-client-1.4.1-beta.jar. Can't the rest of the application use the HttpTransport class that is in gdata-2.2.1-alpha-client-http.jar? (Or the other way around?)

Is this a project for a real business system? I wouldn't use beta- and alpha-versions of libraries for real production code. Aren't there other versions of those libraries available that are matched, so that you don't get this problem?
Destiny's powerful hand has made the bed of my future. And this tiny ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!