With Linux, I'm using a small script to help me find in which jar a class lies that can be used in a find -exec
:
findclass.sh
:
unzip -l "$1" 2>/dev/null | grep $2 >/dev/null 2>&1 && echo "$1"
Basically, as jars are zip, unzip -l
will print the list of class resources, so you'll have to convert .
to /
. You could perform the replacement in the script with a tr
, but it's not too much trouble to do it yourself when calling the script.
The, the idea is to use find
on the root of your classpath to locate all jars, then runs findclass.sh
on all found jars to look for a match.
It doesn't handle multi-directories, but if you carefully choose the root you can get it to work.
Now, find which jar contains class org.apache.commons.lang3.RandomUtils
to you un-mavenize your project (...):
$ find ~/.m2/repository/ -type f -name '*.jar' -exec findclass.sh {} org/apache/commons/lang3/RandomUtils \;
.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar
.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.jar
.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6-sources.jar
$
java -findjar -cp /some/path/with/libs/*.jar my.java.Class
->my.jar
.