Add a breakpoint for ClassCastException
.
For IntelliJ, this looks something like this:

Once the exception is caught, navigate in the debugger call hierarchy until you find the line where the cast should happen and you have a reference to both classes.
For example:

Now, you can inspect both classes (in my case typeClass
and instanceClass
). The class holds a reference to it's class loader.
In my case, it's ModuleClassLoader for Module "my.ear" from Service Module Loader
and
ModuleClassLoader for Module "my-web-app.war" from Service Module Loader

As you can see, one class is coming from the ear, the other one from the war.
Change the dependency to provided
in the web-app pom.xml
, that should solve the problem.
Note that the war file will not run anymore outside of the ear, if you need both scenarios, use a Maven profile.