You can't use reflection for that, since you can only iteract with loaded classes, and only one class can be loaded by a class loader with a specified name.
You have to create separate class loaders (like URLClassLoader), and make the firts one parse the first jar, and the second one should look in the second jar. You can use ClassLoader.loadClass() to load the classes from the jars. More info here and here. It would also be better not to include both versions in the classpath, since the second link suggests it might not work if the system class loader can load the class by itself.
Another option is loading one class, doing whatever you want, unloading it and loading your other class. You can unload a class by:
- Removing all references to the class and its loader, and triggering garbage collection, as stated here.
- Using manipulation tools like ByteBuddy to manipulate the JVM's behaviour.
This would not make it possible to use the classes at the same time, but if you only want to compare or find them it might be sufficient.
If you only want to locate the classes and not use them you can parse the jar files manually and count the appropriate .class files, as explained here.
Short summary: If you have both classes on the classpath, you can only load one of them. If you have neither on the classpath, you can load them both with some manual work. If you only want to find them, parse the jar files.