如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
如何在大量jar文件中找到特定的类名?
(查找实际的类名,而不是引用它的类。)
当前回答
使用unzip (zipinfo)的bash脚本解决方案。在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
其他回答
grep -l "classname" *.jar
告诉你罐子的名字
find . -name "*.jar" -exec jar -t -f {} \; | grep "classname"
给你类的包
不知道为什么这里的脚本从来都不适合我。如此:
#!/bin/bash
for i in *.jar; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done
#!/bin/bash
pattern=$1
shift
for jar in $(find $* -type f -name "*.jar")
do
match=`jar -tvf $jar | grep $pattern`
if [ ! -z "$match" ]
then
echo "Found in: $jar"
echo "$match"
fi
done
只需使用FindClassInJars util,这是一个简单的swing程序,但很有用。您可以在http://code.google.com/p/find-class-in-jars/上查看源代码或下载jar文件
User1207523的脚本对我来说很好。这里有一个变体,使用find隐式搜索jar文件,而不是简单的展开;
#!/bin/bash
for i in `find . -name '*.jar'`; do jar -tf "$i" | grep $1 | xargs -I{} echo -e "$i : {}" ; done