简体   繁体   中英

Class conflict: two jar files with the same classes

I have two jar files with similar Util class names, but different method signatures.

In jar1, I have a main method which must use the method in Util class in jar1. The JVM is linking to Util class in jar2.

How to resolve this class conflict?

If both jar files are loaded into the same classloader then there is no way to determine which class will get loaded. The only way to handle this is to isolate them so only one of them is loaded into the classloader you are using.

You can set up a classloader and only load the jar you want to get the class from, but it is probably much easier to just make sure classes are unique on your path.

Normally one avoids that situation by using appropriate package names, such that they are different.

In extreme situations, where you dont have the choice to change the jar files, there is the option "bootclasspath" where you can specify classes that gets loaded first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM