I'm converting a build that has 71 .jar
files in its global lib/
directory to use Maven. Of course, these have been pulled from the web by lots of developers over the past ten years of this project's history, and weren't always added to VCS with all the necessary version info, etc.
Is there an easy, automated way to go from that set of .jar
files to the corresponding <dependency/>
elements for use in my pom.xml
files? I'm hoping for a web page where I can submit the checksum of a jar file and get back an XML snippet. The google hits for 'maven repository search' are basically just finding name-based searches. And http://repo1.maven.org/ has no search whatsoever, as far as I can see.
Update: GrepCode looks like it can find projects given an MD5 checksum. But it doesn't provide the particular details (groupId
, artifactId
) that Maven needs.
Here's the script I came up with based on the accepted answer:
#!/bin/bash
for f in *.jar; do
s=`md5sum $f | cut -d ' ' -f 1`;
p=`wget -q -O - "http://www.jarvana.com/jarvana/search?search_type=content&content=${s}&filterContent=digest" | grep inspect-pom | cut -d \" -f 4`;
pj="http://www.jarvana.com${p}";
rm -f tmp;
wget -q -O tmp "$pj";
g=`grep groupId tmp | head -n 1 | cut -d \> -f 3 | cut -d \< -f 1`;
a=`grep artifactId tmp | head -n 1 | cut -d \> -f 3 | cut -d \< -f 1`;
v=`grep version tmp | head -n 1 | cut -d \> -f 3 | cut -d \< -f 1`;
rm -f tmp;
echo '<dependency> <!--' $f $s $pj '-->';
echo " <groupId>$g</groupId>";
echo " <artifactId>$a</artifactId>";
echo " <version>$v</version>";
echo "</dependency>";
echo;
done