Today in the project to meet a very interesting problem, tortured me for a long time, but eventually resolved, leave this article to commemorate a moment.
problems encountered: the same piece of code, in the colleague that is, I can not find a method. The quoted package is also the same, this problem is the first time to encounter, how to do? Look for the reason, look at the referenced package, only to find that the package name I refer to is the same as the package name referenced by the colleague, but the difference is that the package I referred to is not a jar. This means that different jars contain the same package name and class name. The cause of the problem has been found, how to solve it? How do you specify the package in the jar you want to call yourself?
To solve this problem, you need to understand how the JVM loads. When the JVM loads the package, it looks from the classpath path from top to bottom, finds the first one and then references it.
Package name class names are the same, the JVM can not distinguish between, the general IDE will prompt a conflict and error, if not error, then only the first package is introduced (in the Classpath path in front of the package), the second package will be ClassLoader load class when the judgment is repeated and ignored.
Knowing the way the JVM loads the package, it's easy to solve the problem by putting the jar that needs to refer to the package in front of you, that is, on top of the classpath path.
Different jar inside the same package name Class name How to distinguish the import