List contents of multiple jar files

前端 未结 9 825
情歌与酒
情歌与酒 2021-02-02 10:50

I am searching for a .class file inside a bunch of jars.

jar tf abc.jar 

works for one file. I tried

find -name \"*.jar\" | xa         


        
相关标签:
9条回答
  • 2021-02-02 11:32

    Here's what I use in Cygwin. It supports section headers per jar file as requested above.

    find . -name "*.jar" \
     -exec echo ======\ {}\ ====== \; \
     -exec /c/Program\ Files/Java/jdk1.7.0_45/bin/jar.exe tf {} \; | less
    

    For *nix, drop the ".exe":

    find . -name "*.jar" \
     -exec echo ======\ {}\ ====== \; \
     -exec jar tf {} \; | less
    
    0 讨论(0)
  • 2021-02-02 11:33

    I faced a similar situation where I need to search for a class in a list of jar files present in a directory. Also I wanted to know from which jar file the class belongs to. I used this below code snippet(shell script) and found out to be helpful. Below script will list down the jar files that contains the class to be searched.

    #!/bin/sh
    LOOK_FOR="codehaus/xfire/spring"
    for i in `find . -name "*jar"`
    do
      echo "Looking in $i ..."
      jar tvf $i | grep $LOOK_FOR > /dev/null
      if [ $? == 0 ]
      then
        echo "==> Found \"$LOOK_FOR\" in $i"
      fi
    done
    

    Shell script taken from : http://alvinalexander.com/blog/post/java/shell-script-search-search-multiple-jar-files-class-pattern

    0 讨论(0)
  • 2021-02-02 11:36

    You can also use -exec option of find

    find . -name "*.jar" -exec jar tf {} \;
    
    0 讨论(0)
  • 2021-02-02 11:36

    Find jar files and get all classes and members saved on a txt.

    (for j in $(find -name '*.jar');do echo "--$j --";jar tf $j | grep .class | sed 's#/#.#g' | sed 's/.class/ /g' | xargs -n 1 javap -classpath  $j ; done;) >> classes.txt
    
    0 讨论(0)
  • 2021-02-02 11:42

    You can also use unzip which is more faster than jar (-l option to print zip content).

    For instance, a small script that does roughly what you want:

    #!/bin/bash
    
    for i in $(find . -name "*.jar")
    do
        if [ -f $i ]
    then
        echo $i
        unzip -l $i | grep $*
    fi
    done
    
    0 讨论(0)
  • 2021-02-02 11:45

    I don't see the necessity for using exec, this worked for me in Cygwin on Windows:

    find . -name "*.jar" | while read jarfile; do unzip -l $jarfile | fgrep "foo" ; done 
    
    0 讨论(0)
提交回复
热议问题