tags:

views:

56

answers:

2

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&amp;content=${s}&amp;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
A: 

Hi you can use mvnrepository to search for artifacts or you can use Eclipse and go through the add dependency there is a search which is using the index of maven central.

khmarbaise
+3  A: 

Jarvana can search on a digest (select digest next to the Content input field).

For example, a search on d1dcb0fbee884bb855bb327b8190af36 will return commons-collections-3.1.jar.md5. Then just click on the alt text icon to get the details (including maven coordinates).

One can imagine automating this.

Pascal Thivent