Re: help: class conflict in two different version JAR files
On 3/20/2013 10:34 AM, zyng wrote:
I am using Eclipse. Project A uses 3rdparty.1.0.1.jar file; Project B
uses 3rdparty.1.0.3.jar file. Project B depends on Project A.
I am working on Project B. I am not supposed to change anything in
Project A. I hope that the code in B always use the class inside
3rdparty.1.0.3.jar. I don't know how to do that. I found that for the
classes in 3rdpartyxx.jar, the code in B just use the class in
3rdparty.1.0.1.jar file, which is used by A. I guess since B depends
on A, so 3rdparty.1.0.1.jar file has the higher priority. This causes
some problem, which I just omit here.
If running by ANT on the command line, due to the way I set
up(project A's code listed near the end of the Java classpath), the
code in B uses the classes in 3rdparty.1.0.3.jar and the problem was
avoided.
This can be a tricky problem.
The easy and practical solution is to try and run with a.jar b.jar and
3rdparty.1.0.3.jar.
In many/most cases it will work because 1 version 1.0.3 should be
compatible with version 1.0.1.
If it does not then you will need to make changes so that
a.jar and 3rdparty.1.0.1.jar are loaded by one classloader and
b.jar and 3rdparty.1.0.3.jar are loaded by another classloader.
That is possible, but will require some coding.
I suggest that you try the easy approach first.
Arne