简体   繁体   English

两个具有相同包名,相同类名和相同方法名的罐子

[英]Two jars having same package name, same class name and same method name

I am facing this problem in spring boot application where I am using Two jars. 我在使用两个罐子的spring boot应用程序中遇到此问题。 And in those jars there are two classes with the same package name and same class name and one method with the same name . 在这些jar中,有两个类具有相同的程序包名称和相同的类名称,以及一个方法具有相同的名称。 Problem occurs when class loader loads the class from different jar and tries to call this method, If jar A is loaded first then method is called and everything works fine , But if jar B is called first then, NOSUCHMETHODERROR exception is thrown at runtime. 当类加载器从不同的jar加载类并尝试调用此方法时,会发生问题。如果首先加载jar A,则调用方法,并且一切正常,但是如果首先调用jar B,则在运行时引发NOSUCHMETHODERROR异常。 Can you please help to fix this. 您能帮忙解决此问题吗? Is there a way by which I can force the classloader to load a particular jar first, always in Spring boot app, Or probably any other fix for this. 有没有一种方法可以强制类加载器首先在Spring Boot应用程序中首先加载特定的jar,或者可能对此进行任何其他修复。

NOTE: I am using JAVA 8 and I don't have access to the source code of these jar files. 注意:我正在使用JAVA 8,但无权访问这些jar文件的源代码。

If you are loading those jars as a dependency you could exclude it from Maven via 如果您将这些罐子作为依赖项加载,则可以通过以下方式将其从Maven中排除

<exclusions>
   <exclusion>
       <groupId>org.XXXX</groupId>
        <artifactId>jar1-api</artifactId>
    </exclusion>
</exclusions> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有相同类文件名称和相同包结构的jar - Jars with same name of class file and with same package structure 如果不同的 jars 在插件 Z68995FCBF432492D15484D04A9D2AC4 中具有相同的 class 名称,则访问 class - Accessing class if different jars having same class name in plugin jar Java class 调用两个 jars 具有相同的 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61ZD - Java class calling two jars which has same class and method name 当两个相同的类具有相同的名称、package 和内容时,如何解决 class 转换异常? - How to resolve class cast exception when two same classes having same name, package and content? 我在不同的jar中有两个具有相同名称和相同包结构的类。 是否可以从jar中专门选择一个类? - I have two classes with same name and same package structure in different jars. Is it possbile to choose a class from jar specifically? 包名称和类名称与框架相同 - same package name and class name with framework Java类名与嵌套包名相同 - Java class name same as the nested package name 具有相同名称的线程 - threads having the same name 扩展类和实现的接口具有相同的方法名称 - Extended Class And implemented interface having same method name 具有相同程序包名称和相同类名称的两个不同的.jar。 如何获得一个? - Two different .jar with same Package name and same Class name. How to get the one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM