[英]Class conflict: two jar files with the same classes
I have two jar files with similar Util class names, but different method signatures. 我有两个jar文件,它们的Util类名称相似,但方法签名不同。
In jar1, I have a main method which must use the method in Util class in jar1. 在jar1中,我有一个main方法,该方法必须使用jar1中Util类中的方法。 The JVM is linking to Util class in jar2.
JVM链接到jar2中的Util类。
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. 如果两个jar文件都加载到同一个类加载器中,则无法确定要加载哪个类。 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. 您可以设置一个类加载器,并仅加载您要从中获取该类的jar,但是仅要确保类在您的路径上唯一可能要容易得多。
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. 在极端的情况下,如果您没有选择更改jar文件的选项,则可以使用“ bootclasspath”选项来指定要首先加载的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.