[英]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.