help: class conflict in two different version JAR files

Z

zyng

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.

I hope to solve the problem in Eclipse. Thank you for your help.
 
Z

zyng

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 isused 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.



I hope to solve the problem in Eclipse. Thank you for your help.

Another thing I am unclear is that: in the code in Project B, in Eclipse, when I press F3 on one of the class names, it says no source attached in 3rdparty.1.0.3.jar, giving me the impression that the code is using the classes in 3rdparty.1.0.3.jar. However, when running, the code is definitely using the classes in 3rdparty.1.0.1.jar, not 3rdparty.1.0.3.jar.

For example: In Eclipse, if I remove 3rdparty.1.0.1.jar from Project A's build path, some code of A has compiling errors. But it does not matter for this testing purpose. Now, if I run my JUNit test code in Project B, the correct classes are used and the problem was avoided.
 
L

Lew

zyng said:
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.

Advice #1: Build your project using Ant and command-line tools. That will help you understand
what Eclipse is doing.
I am working on Project B. I am not supposed to change anything in Project A. I hope that the code in

Ideally Project A will come to Project B as a JAR, e.g., "projectA.jar".
B always use the class inside 3rdparty.1.0.3.jar. I don't know how to do that. I found that for the

This is not really the way to look at it. One moment ...
classes in 3rdpartyxx.jar, the code in B just use the class in 3rdparty.1.0.1.jar file, which is used by A.

That is because both JARs are in your classpath.

I guess since B depends on A, so 3rdparty.1.0.1.jar file has the higher priority.

That is not correct.

It is because "3rdparty.1.0.1.jar" is ahead of "3rdparty.1.0.3.jar" in the classpath.

Just remove "3rdparty.1.0.1.jar" from the classpath.
This causes some problem, which I just omit here.

Problems that the Project B cannot compile because it uses a newer version of "3rdparty".

But of course.

Unless "3rdparty" really screwed up backwards compatibility, remove the old version from
the classpath.

Otherwise, put Project A after "3rdparty.1.0.3.jar" in your classpath for Project B.
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.

Read up on classpaths.
I hope to solve the problem in Eclipse. Thank you for your help.

Have Eclipse use the Ant build.xml.
 
L

Lew

zyng said:
For example: In Eclipse, if I remove 3rdparty.1.0.1.jar from Project A's build path, some code

Did you remember to put version 1.0.3 in Project A's build path?
of A has compiling errors. But it does not matter for this testing purpose. Now, if I run my
JUNit test code in Project B, the correct classes are used and the problem was avoided.

Project A should not have trouble using a more recent version of the JAR.
 
A

Arne Vajhøj

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
 
R

Roedy Green

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.

I hope to solve the problem in Eclipse. Thank you for your help.

If the authors did this properly, all you need to do is hide the 1.0.1
jar, get in off the classpath, out of the ext dirs, and all should
work. At run time Java looks for matching class files.

If it does not, you will have to recompile Project A, and modify it
slightly to use the new jar, e.g. a renamed class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top