简体   繁体   English

我的 Java 应用程序中的两个类具有相同的限定名称

[英]Two classes in my java app have the same Qualified name

I have maven module setup and one class is present in two modules with same name and package structure.我有 maven 模块设置,一个类存在于两个具有相同名称和包结构的模块中。 com.expd.common.etms_functions_shared_service_types.v2.ExportConsol

These classes are generated during a maven build.这些类是在 maven 构建期间生成的。 One from a wsdl and the other from avro schema and both the wsdl and avro schema are not in our control.一个来自 wsdl,另一个来自 avro 模式,wsdl 和 avro 模式都不受我们控制。 The app picks up only 1 at run time excluding the other which is expected.应用程序在运行时仅选取 1 个,排除预期的另一个。

Is there a way I can use both without having to rename them or change the package name?有没有一种方法可以同时使用它们而不必重命名它们或更改包名称?

Sure, you can. 你当然可以。 You need keep these classes in separate class loaders, so they naturally did NOT know about each other. 您需要将这些类保存在单独的类加载器中,因此他们自然不会彼此了解。

However renaming (eg using maven shade plugin ) would be much simpler and convenient solution. 然而,重命名(例如使用maven shade插件 )将是更简单和方便的解决方案。

If you don't separate class loader the basic beahvior is that if the same class with FQN is just loaded the second occurrence during class discovery will be ignored.如果您不分离类加载器,则基本行为是,如果刚刚加载了与 FQN 相同的类,则在类发现期间的第二次出现将被忽略。 So i'm suggesting to keep one version of your class during class loading, deploying one jar containing that class in order to avoid confusion.所以我建议在加载类时保留一个版本的类,部署一个包含该类的 jar 以避免混淆。

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

相关问题 在运行时在 Java 中查找具有相同全限定名的类 - Find classes with same full qualified name in Java during runtime 两个类具有相同的 XML 类型名称 - Two Classes have same XML type name 在Java中使用两个具有相同名称的类 - Using two classes with same name in java 磁盘上的.class文件是否必须遵循与其Java中限定名称相同的目录结构才能运行? - Does a .class file on disk have to follow the same directory structure as its qualified name in Java for us to run it? wsdl2java两个类具有相同的XML类型名称“{http://***.***。$。* * / * / / / / / *}} objectFactory” - wsdl2java Two classes have the same XML type name “{http://***.***.***.***/***/***/***}objectFactory” java +消费SOAP Web服务+“两个类具有相同的XML类型名称……” - java + Consuming a SOAP web service + “Two classes Have the same XML type name …” 在Java中更改Import的名称,或导入两个同名的类 - Change Name of Import in Java, or import two classes with the same name 可以使用两个具有相同名称和相同包的java类吗? - Possible to use two java classes with same name and same package? Java - 两个类,名称相同,包相同,但在不同的文件夹中 - Java - Two classes, same name, same package but in different folders 在不同的包中有两个同名的类的坏习惯? - Bad practice to have two classes of the same name in different packages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM