Two classes in my java app have the same Qualified name

Viewed 204

I have maven module setup and one class is present in two modules with same name and package structure. com.expd.common.etms_functions_shared_service_types.v2.ExportConsol

These classes are generated during a maven build. One from a wsdl and the other from avro schema and both the wsdl and avro schema are not in our control. The app picks up only 1 at run time excluding the other which is expected.

Is there a way I can use both without having to rename them or change the package name?

2 Answers

Sure, you can. You need keep these classes in separate class loaders, so they naturally did NOT know about each other.

However renaming (e.g. using maven shade plugin) would be much simpler and convenient solution.

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. 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.

Related