1

related: manage conflict on java classpath

also related: Java Classloader - how to reference different versions of a jar

I have two jar files in my which in each own has it own dependency included in jar file but both of them is in different version.

a.jar -> has c.class/c2.class/c3.class/.. version 0.3 in it

b.jar -> has c.class/c2.class/c3.class/.. version 1.0 in it

But when I tried to use both of them in the same project. It seems like it only use c.class from one jar but not another. This turn out to be a problem since API is very different in both version. Is there anyway to tell them to use a c.class just from its respective jar ? I can't modified a.jar and b.jar here.

btw. After quick search it seems like people suggest OSGI and classloader but I know next to nothing about it which should be the quickest way to deal with it ? (already read a little bit about classloader but still not sure how to use it).

EDIT: I prefer to use original library they bundle with since I already evaluated those two jar separately (they are text mining tools with same back-end but the version is very different). Now I want to integrate both of them into one and try to make the environment close to original as possible. Right now I follow Travis Webb's solution but I still wonder why the jar don't separate both set of library.

Community
  • 1
  • 1
Tg.
  • 5,608
  • 7
  • 39
  • 52

1 Answers1

3

Quickest way:

Extract a.jar, delete the stuff you don't want, and re-jar it. A JAR is identical to a zip file, which means you can just create a normal zip file and rename it to a .jar.

btw, this is not your fault. Whoever you got those jars from are idiots, because they included external dependencies in with their releases, and they aren't supposed to do that.

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
  • thanks, I tried your solution and it worked although quite a little bit different from my original goal (separate their environment). btw. these program spawned from biomedical field where the normal software practice is next to non-existence. – Tg. Dec 04 '11 at 02:45
  • I think we should be diligent enough to cross verify jars by ensuring that it serves only our interests . – sskumar86 Aug 17 '16 at 10:06