Monday, August 11, 2008

Using find to locate duplicate or missing classes

I found this super useful find command on the webspherehelp blog which I am pasting below:
find . -name '*.jar' -o -name '*.war' -o -name '*.ear' -type f |xargs -i bash -c "jar -tvf {}| tr / . | grep CLASSNAME && echo {}"
Just change the sample Classname to the one you are getitng a conflict with.
It will search though all files in the current directory (or whereever you point the find command) and locate every class file which matches the CLASSNAME text. Very useful.
I needed this to track down a java.lang.LinkageError recently and it worked like a charm.
Here is the original blog posting.