我是靠谱客的博主 细心冥王星,最近开发中收集的这篇文章主要介绍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;

}

}

最后

以上就是细心冥王星为你收集整理的java 获取pom文件位置_根据jar包批量获取对应的pom.xml文件的全部内容,希望文章能够帮你解决java 获取pom文件位置_根据jar包批量获取对应的pom.xml文件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部