欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java根据本地jar包l,生成pom配置文件,及将本地jar包上传私服命令

程序员文章站 2022-07-15 10:17:23
...

java根据本地jar包,生成pom配置文件,及将本地jar包上传私服命令:
代码如下:
package com.project.test;

import java.io.File;

public class Test {
public static void main(String[] args) {

	String c= getDependencyStr();
	System.out.println(c);
	//String b =  getMavInstallStr();
	//System.out.println(b);
	//test();
    } 
 public static String  getDependencyStr(){
	
        String strPatha = "jar包的路径";//例如:
        String strPatha = "E:\\proCodeSpace\\test\\WebRoot\\WEB-INF\\lib";
        File dir = new File(strPatha);
        String _content = "";
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                String fileName = files[i].getName();
                String fileName2 = fileName.replace(".jar", "");
                String version = fileName2.substring(fileName2.lastIndexOf("-")+1,fileName2.length());
                if(version==null ||"" .equals(version) || version.indexOf(".") == -1){
                	version="1.0.0";
	            } 
                if(version.indexOf(".RELEASE") != -1){
                	version = version.replace(".RELEASE", "");
                }
                _content += "        <dependency>\n";
                _content += "            <groupId>" + fileName2 + "</groupId>\n";
                _content += "            <artifactId>" + fileName2 + "</artifactId>\n";
                _content += "            <version>"+version+"</version>\n";

// _content += " system\n";
// _content += " ${lib.dir}/" + fileName + “\n”;
_content += " \n\n";
}
}
return _content;
}

 public static String  getMavInstallStr(){
        String strPatha = "E:\\proCodeSpace\\test\\WebRoot\\WEB-INF\\lib";
        File dir = new File(strPatha);
        String _content = "";
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                String fileName = files[i].getName();
                String fileName2 = fileName.replace(".jar", "");
                String version = fileName2.substring(fileName2.lastIndexOf("-")+1,fileName2.length());
                if(version==null ||"" .equals(version) || version.indexOf(".") == -1){
                	version="1.0.0";
	            } 
                if(version.indexOf(".RELEASE") != -1){
                	version = version.replace(".RELEASE", "");
                }
                _content += "mvn install:install-file -Dfile=E:\\proCodeSpace\\test\\WebRoot\\WEB-INF\\lib\\"+fileName;
                _content += " -DgroupId="+fileName2;
                _content += " -DartifactId="+fileName2;
                _content += " -Dversion="+version+" -Dpackaging=jar\n\n";
            }
        }
        return _content;
 }
 
 public static void  test(){  
	 String strPatha = "E:\\proCodeSpace\\test\\WebRoot\\WEB-INF\\lib";
     File dir = new File(strPatha);
     File[] files = dir.listFiles();
     if (files != null) {
         for (int i = 0; i < files.length; i++) {
        	String fileName = files[i].getName();
        	String fileName2 = fileName.replace(".jar", "");
            String version = fileName2.substring(fileName2.lastIndexOf("-")+1,fileName2.length());
            if(version==null ||"" .equals(version) || version.indexOf(".") == -1){
            	System.out.println(fileName2);
            }
         }
     }
 }

}
生成的pom文件内容如下:
只需将控制台输出的信息拷贝到pom文件
java根据本地jar包l,生成pom配置文件,及将本地jar包上传私服命令
生成的上传maven私服的命令如下:

java根据本地jar包l,生成pom配置文件,及将本地jar包上传私服命令