JarScan, scan all JAR files in all subfolders for specific class

后端 未结 8 2180
一个人的身影
一个人的身影 2020-12-29 13:03

We are seeing an older version of a class being used, although we had the latest one deploy. To scan all JAR files in all subfolders of an application server, how do we writ

相关标签:
8条回答
  • 2020-12-29 13:22

    Not directly answering your question, but maybe this will solve your problem: you can print out the location (e.g. the jar file) from which a specific class was loaded by adding a simple line to your code:

    System.err.println(YourClass.class.getProtectionDomain().getCodeSource());
    

    Then you will know for sure where it comes from.

    0 讨论(0)
  • 2020-12-29 13:22

    If you need result only then you can install agentransack http://www.mythicsoft.com/agentransack/ and do a containing text search. Agentransack searches inside jar and zip files as well.

    0 讨论(0)
  • 2020-12-29 13:25

    The tool JAR Explorer is pretty useful.

    It pops open a GUI window with two panels. You can pick a directory, the tool will scan all the JAR files in that directory, then let you search for a specific class. The lower panel then lights up with a list of hits for that class in all the scanned JAR files.

    0 讨论(0)
  • 2020-12-29 13:26

    Something like:

    find . -name '*.jar' | while read jarfile; do if jar tf "$jarfile" | grep org/jboss/Main; then echo "$jarfile"; fi; done
    

    You can wrap that up like this:

    jarscan() {
      pattern=$(echo $1 | tr . /)
      find . -name '*.jar' | while read jarfile; do if jar tf "$jarfile" | grep "$pattern"; then echo "$jarfile"; fi; done
    }
    

    And then jarscan org.jboss.Main will search for that class in all jar files found under the current directory

    0 讨论(0)
  • 2020-12-29 13:27

    You may also want to have a look at the Java tool JarScan.

    One can search by class name and by package.

    It helps a lot when Total Commander isn't available and only Java is allowed to execute.

    0 讨论(0)
  • 2020-12-29 13:41
    #! /bin/sh
    
    path=$1
    segment=$2
    
    if [ -z "$path" ] || [ -z "$segment"  ]
    then 
        echo "Usage: $0 <path> <segment>"
        exit
    fi
    
    for jar in $path/*.jar ; do echo " *** $jar *** " ; jar tf $jar| grep --color=always $segment; done;
    
    0 讨论(0)
提交回复
热议问题