Find a specific class in your maven repository
If you don’t want to use findjar, you can use a groovy script.
You can use the following:
It will search recursively all jar files under ‘/home/USER/.m2/repository’, just adjust the value for ‘USER’.
Please excuse the poor formatting of the code, I blame the browser for it
import java.util.jar.JarFile
if (args?.size() == 0 || args[0]?.length() == 0)
{
println "usage with Parameters:
println "per default /home/USER/.m2/repository will be searched"
println
System.exit(1)
}
def searchingClass = args[0]
def folder = args.size() > 1 ? args[1] : "/home/knm/.m2/repository"
println "groovy searching for Class $searchingClass in $folder"
def basedir = new File(folder)
// gets all jar-files in basedir
jars = []
public void recursedirs(File filedir)
{
filedir.listFiles().each
{ file ->
if (file.isFile() && file.name.endsWith("jar") )
{ jars << file }
else if (file.isDirectory() )
{ this.recursedirs(file) }
}
}
recursedirs( basedir)
files = jars
for (currentFile in files)
{
try {
new JarFile(currentFile).entries().each {entry ->
if (entry.name =~ searchingClass)
{
tmp = entry.name.replaceAll("/", ".").replaceAll(".class", "")
println "$tmp ===> $folder/$currentFile.name"
}
}
}
catch (Throwable t)
{
println "\nFailed to open $currentFile.canonicalPath: ${t.toString()}"
}
}