在Maven存储库中找到正确的JAR的正确版本 [英] Finding the right version of the right JAR in a maven repository

查看:260
本文介绍了在Maven存储库中找到正确的JAR的正确版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在转换一个在其全局lib/目录中具有71个.jar文件的版本,以使用Maven.当然,在此项目的过去十年中,许多开发人员已将这些内容从网络上撤下,并且并不总是将其与所有必要的版本信息一起添加到VCS中.

是否有一种简单,自动化的方法来将这组.jar文件转换为相应的<dependency/>元素以用于我的pom.xml文件?我希望找到一个网页,在其中可以提交jar文件的校验和并获取XML代码段.谷歌的"Maven存储库搜索"命中基本上只是在寻找基于名称的搜索.据我所知, http://repo1.maven.org/完全没有搜索. /p>

更新: GrepCode 看起来可以找到具有MD5校验和的项目.但是它没有提供Maven所需的特定细节(groupIdartifactId).

这是我根据公认的答案得出的脚本:

#!/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

解决方案

Jarvana 可以在以下位置搜索摘要(在 Content 输入字段旁边选择摘要).

例如,在 图标以获取详细信息(包括Maven坐标).

可以想象自动做到这一点.

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

解决方案

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

For example, a search on icon to get the details (including maven coordinates).

One can imagine automating this.

这篇关于在Maven存储库中找到正确的JAR的正确版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆