Skip to content

Instantly share code, notes, and snippets.

@PauloMigAlmeida
Created August 12, 2015 19:52
Show Gist options
  • Save PauloMigAlmeida/1b38830b99f48095b9da to your computer and use it in GitHub Desktop.
Save PauloMigAlmeida/1b38830b99f48095b9da to your computer and use it in GitHub Desktop.
Search Java class within a directory. It's particularly useful when dealing with Maven conflicts.
#!/bin/bash
# Usage ./find_class_directory.sh <folder> <class>
# Example: ./find_class_directory.sh WEB-INF/lib SignatureReader
TARGET_DIR=$1
TARGET_CLASS=$2
LIST_FILES=$(ls -1 $TARGET_DIR | grep -i -e ".*\.jar")
while read -r line; do
FOUND_CLASSES_IN_JAR=$(unzip -l $TARGET_DIR/$line | awk '{print $4}' | tail -n +4 | grep $TARGET_CLASS)
if [ -n "$FOUND_CLASSES_IN_JAR" ]
then
echo "Found $FOUND_CLASSES_IN_JAR in $line"
fi
done <<< "$LIST_FILES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment