Search This Blog

Friday, 30 October 2009

how to find a Java class inside a set of jar files

These are commands to be run from the shell to locate a Java class into a set of jar files, usually in a WEB-INF/lib directory in a J2EE application server.

On Windows
Make sure to run the script from a dos console with the delayed environment variable expansion option enable, that is cmd /V:ON

The script is to be called with two arguments, the first is the folder where to search in, the second is the class name

echo off
FOR /F %%G IN ('DIR /S /B /S %1\*.jar') DO (
echo %%G
jar -tf %%G | findstr %2

On *nix
find -ls -exec sh -c '/usr/jdk1.5.0_07/bin/jar tf $1 | 
grep JavaClass.class' {} {} \;

where /usr/jdk1.5.0_07 is the path where the JDK resides and JavaClass.class is the class name to be searched

No comments:

Post a Comment