i have two versions of same library , say abc-1.0.jar and abc-2.0.jar i cant avoid either for my application to work , parts of the code are not yet migrated to 2.0 how do i force a class object and methods to be from abc-2.0.jar ? but not from 1.0.jar in my module.
any help greatly appreciated !
Regards Sasha开发者_开发问答nk
There is no totally general, and yet simple solution.
The simplest solution is put the 2 JAR files on the classpath, with the 2.0 JAR file ahead of the 1.0 JAR file. This will probably work for your use case, but it won't work if the there are cases where you need to use the older version of some class.
Another solution is to put the class in question into a new JAR file and put it on the classpath ahead of both the 1.0 and 2.0 JAR files. But reorganizing the JAR files may not be an option.
The complicated way is to write a custom classloader for the 1.0 and 2.0 JAR files. This is a lot of work, and probably unnecessary.
If, whenever there is an ambiguity (same class in both jars) you want to use the 2.0 jar, then you can just ensure that the 2.0 jar is before the 1.0 jar on your classpath.
If it's just one (or a few) classes where you want to use the 2.0 jar, and others where you want to use the 1.0 jar, the problem becomes considerably more complicated.
精彩评论