maven命令安装本地jar包到本地仓库-动态命令
由于工作需要经常使用
将本地jar包加入到maven仓库的命令:mvn install:install-file -Dfile=C:\Users\admin\Downloads\xxxx.jar -DgroupId=org.springframework -DartifactId=spring -Dversion=0.0.1.RELEASE -Dpackaging=jar
今天就做了一个封装可以生成动态命令使用
/**
* @author pqYang
* @Date 22:11 2019/5/25
**/
public class PomUtil {
public static void main(String[] args) {
String target ="<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->\n" +
"<dependency>\n" +
" <groupId>org.mybatis</groupId>\n" +
" <artifactId>mybatis</artifactId>\n" +
" <version>3.4.6</version>\n" +
"</dependency>\n";
//下载jar包名与pom文件名不一致使用
installPom("C:\\Users\\admin\\Downloads","mybatis-3.4.6", target);
//下载jar包默认名
installPom("C:\\Users\\admin\\Downloads",getdefaultjarname(target), target);
}
/*
* @Param target pom名字* @Author pqYang
* @return java.lang.String 下载jar包默认名**/
public static String getdefaultjarname(String target) {
if (target =="") {
return target;
}else {
String artifactId = target.substring(target.indexOf("artifactId") +11, target.indexOf("/artifactId") -1);
String version = target.substring(target.indexOf("version") +8, target.indexOf("/version") -1);
return artifactId+"-"+version;
}
}
/*
* @Param filepath 你的下载路径名 * @Param jarname 你下载的jar包名 * @Param target pom名字* @Author pqYang
* @return void
**/
public static void installPom(String filepath, String jarname, String target) {
if (target =="") {
return;
}else {
if (target.contains("artifactId") && target.contains("groupId") && target.contains("version")) {
String installPomString ="";
String pom ="mvn install:install-file -Dfile=C:\\Users\\admin\\Downloads\\xxxx.jar -DgroupId=org.springframework.boot -DartifactId=spring -Dversion=0.0.1.RELEASE -Dpackaging=jar";
StringDgroupId= target.substring(target.indexOf("groupId") +8, target.indexOf("/groupId") -1);
String artifactId = target.substring(target.indexOf("artifactId") +11, target.indexOf("/artifactId") -1);
String version = target.substring(target.indexOf("version") +8, target.indexOf("/version") -1);
if (filepath.equals("C:\\Users\\admin\\Downloads")) {
installPomString = pom.replace("xxxx", jarname).replace("org.springframework.boot", DgroupId).replace("spring", artifactId).replace("0.0.1.RELEASE", version);
}else {
installPomString = pom.replace("C:\\Users\\admin\\Downloads", filepath).replace("xxxx", jarname).replace("org.springframework.boot", DgroupId).replace("spring", artifactId).replace("0.0.1.RELEASE", version);
}
System.out.println(installPomString);
}
}
}
}