I am deploying a JAR file to the Tomcat WEB-INF\lib
folder and the classes or JavaBeans referenced in such JARs are being consumed properly by the other parts of Java code in the web application.
When I repeated the same steps on a different machine (UAT), with another similar Tomcat server instance (to test the application on UAT) I got an error indicating that the class is duplicated in two JAR files but I don't remember the exact error. I looked up the WEB-INF\lib
folder and it took me some extensive effort to locate the culprit JAR file and remove it from the folder and everything worked fine.
The strange thing is that the same deployment is repeated on staging (to verify before production deployment) and I didn't get the error, and everything was fine, despite the fact that there was another JAR file with the same class and same package names.
Questions:
If there are multiple references to the same Java Class in more than one JAR files, how we can confirm which one is picked up by Tomcat server? I am able to verify by checking the log and searching for certain keywords I am sending to the log using debug statements. But, how to check that from Tomcat?
How I can search all the JARs in the lib folder for a possible duplicate reference of the Java class or package?
Answer is provided here: https://stackoverflow.com/a/1343026Why in one instance the duplicate class declaration error was thrown and in another instance, it was not thrown although it should have been thrown?
Is there a configuration to indicate if there are duplicate class declarations in multiple JARs to resolve the reference following certain criteria? Where is such config?
What are the recommended practices to deploy the JAR file with a new version of the class? Is it simple to copy/paste the new JAR and replace the existing file?
I appreciate your help. Tarek