Alex Rivera | Logout

Find a class somewhere inside dozens of JAR files?

Asked 2009-08-27T18:23:46.687
312

How would you find a particular class name inside lots of jar files?

(Looking for the actual class name, not the classes that reference it.)

Edit
Report

2 Answers

3

A bash script solution using unzip (zipinfo). Tested on Ubuntu 12.

#!/bin/bash

# ./jarwalker.sh "/a/Starting/Path" "aClassName"

IFS=$'\n'
jars=( $( find -P "$1" -type f -name "*.jar" ) )

for jar in ${jars[*]}
    do
        classes=( $( zipinfo -1 ${jar} | awk -F '/' '{print $NF}' | grep .class | awk -F '.' '{print $1}' ) )
        if [ ${#classes[*]} -ge 0 ]; then
            for class in ${classes[*]}
                do
                    if [ ${class} == "$2" ]; then
                        echo "Found in ${jar}"
                    fi
                done
        fi
    done
answered 2013-06-27T14:01:33.720
2

To add yet another tool... this is a very simple and useful tool for windows. A simple exe file you click on, give it a directory to search in, a class name and it will find the jar file that contains that class. Yes, it's recursive.

http://sourceforge.net/projects/jarfinder/

answered 2013-07-19T11:57:06.367

Your Answer