1

In my project we are referencing lot of dependency .jar files.

/lib/xxx.jar /lib/abc.jar

The xxx.jar file having some (com.search.hit) packages. The same packages are available in abc.jar file.But the problem comes into picture now, where accessing xxx.jar file it doesn't referencing their package(com.search.hit) instead it is referencing abc.jar package.

Could anyone tell how to redirect the flow?

Cœur
  • 37,241
  • 25
  • 195
  • 267
sanjay
  • 45
  • 1
  • 8
  • You must resolve the underlying issue of having multiple sources of same classes. This will *always* bring in errors. – Marko Topolnik Jul 01 '13 at 08:09
  • Is there any possibility of re-ordering the class-path.? will solve the above problem.? – sanjay Jul 01 '13 at 08:14
  • No, it won't. You may get your immediate issue, involving one specific class, resolved, but it will be back with another class, which will now want you to revert the classpath to original order... you get the picture. – Marko Topolnik Jul 01 '13 at 08:15

4 Answers4

0

The class from whichever jar comes first on the classpath is the one that is used. The other one might not even exist as far as the classloader is concerned. It's a good idea to avoid conflicts like this.

AllTooSir
  • 48,828
  • 16
  • 130
  • 164
0

In Eclipse go to your project build path configuration and click on the Libraries tab. Then remove the package that you don't want to be accessed from your list and add it again.

This will cause the package to be lower in the priority list and it'll check the other package before the one you just re-added.

JREN
  • 3,572
  • 3
  • 27
  • 45
0

This will create problems for you. My suggestion would be to create 2 extra classes for writing getter and setter wrappers for these jar files. Write 2 seperate classes, each one of them will reference just one of them and your project file will use these wrapper classes to invoke functions from these jars. It would be a lot easier that way.

voidMainReturn
  • 3,339
  • 6
  • 38
  • 66
0

You have to change the package name it can not be same file name with same package in single JVM. JVM will take load randomly one jar class using class loader and ignore the rest.

Nitin
  • 3,533
  • 2
  • 26
  • 36