Useful command to find conflicting Java classes

Posted by ryan
at 9:19 PM on Thursday, December 08, 2005

I had the need awhile ago to find if any jar files in my app included the same class files. On *nix you can do it using this command (which will recursively search all jars in the current directory and compare them to jars in the otherDir directory:

find ./ -name "*.jar" -type f -print | xargs -i -t jar -tf {} |
   grep .class | xargs -i -t grep {} ../<i>otherDir</i>/*.jar |
   grep matches > matches.txt

I’m sure there’s a slicker way of doing it, but it worked for me…

Comments

Leave a response