java 获取pom文件位置_根据jar包批量获取对应的pom.xml文件

代码有问题,不够严谨,暂做记录。

package com.io;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.regex.Pattern;

import org.jsoup.Jsoup;

import org.jsoup.helper.StringUtil;

public class JarToPom {

public static void main(String[] args) throws FileNotFoundException, IOException {

// Element dependencys = new DOMElement("dependencys");

File files = new File("D:\\webJar"); //lib目录

/*File[] jars = files.listFiles(new FilenameFilter() {

@Override

public boolean accept(File dir, String name) {

return name.endsWith(".jar");

}

});*/

for (File jar : files.listFiles()) {

String jarname = jar.getName();

int index = jarname.lastIndexOf("-");

int jarIndex = jarname.lastIndexOf(".");

if(!jarname.contains("-")){

System.out.println("");

System.out.println("该jar包不存在版本号");

continue;

}

String bundleName = jarname.substring(0,index);

String bundleVersion = jarname.substring(index +1 ,jarIndex);

if (bundleName ==null || bundleVersion == null){

System.out.println("");

System.out.println();

continue;

}

Pattern p = Pattern.compile(".*\\d+.*");

if(!p.matcher(bundleVersion).matches()){

System.out.println("");

System.out.println("该jar包不存在版本号");

continue;

}

System.out.println("");

System.out.println(getDependices(bundleName,bundleVersion));

System.out.println();

}

}

public static String getDependices(String key, String ver) {

String url ="https://mvnrepository.com/search?q="+key;

org.jsoup.nodes.Document doc = null;

try {

doc = Jsoup.connect(url).ignoreContentType(true).timeout(60000).get();//ignoreContentType(true) ,这个是忽略请求类型

} catch (IOException e) {

e.printStackTrace();

}

org.jsoup.nodes.Element elem = doc.body();

String href = elem.childNodes().get(1).childNodes().get(2).childNodes().get(2).childNodes().get(0).attributes().get("href");//应该拿所有的,而不是第一个

if("".equals(href)||null==href){

return "中央仓库未查到";

}

String[] jarinfo = href.split("/");// /artifact/javax.activation/activation /artifact/org.activiti/activiti-bpmn-converter

String result = "\n" +

" "+jarinfo[2]+"\n" +//此处还应该判断名字是否相同

" "+key+"\n" +

" "+ver+"\n" +

"";

return result;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值