1.手动上传
2.脚本上传
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=1.0.0 -Dpackaging=jar -Dfile=D:/repository/ojdbc-1.0.0.jar -Durl=http://192.168.5.128:8081/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty
java循环遍历maven库生成脚本
package whj;
import java.io.File;
public class DocumentTraversal {
public static void main(String[] args) {
String path = "D:\\repository";
traverseFolder2(path);
}
/**
* 递归目录
*
* @param path
*/
public static void traverseFolder2(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (null == files || files.length == 0) {
System.out.println("文件夹是空的!");
return;
} else {
for (File file2 : files) {
if (file2.isDirectory()) {
traverseFolder2(file2.getAbsolutePath());
} else {
String absolutePath = file2.getAbsolutePath();
String fileName = file2.getName();
if (fileName.endsWith(".jar")) {
String parent = file2.getParent();
String realPath = parent.split("D:\\\\repository\\\\")[1];
String[] groupPath = realPath.split("\\\\");
String Dversion = groupPath[groupPath.length - 1];
String DartifactId = groupPath[groupPath.length - 2];
String DgroupId = "";
for (int i = 0; i < groupPath.length; i++) {
if (i != groupPath.length - 1 && i != groupPath.length - 2) {
if (i == 0) {
DgroupId = groupPath[i];
} else {
DgroupId = DgroupId + "." + groupPath[i];
}
}
}
// System.out.println("Dfile:" + absolutePath);
// System.out.println("DgroupId:" + DgroupId);
// System.out.println("DartifactId:" + DartifactId);
// System.out.println("Dversion:" + Dversion);
// System.out.println();
MavenEntity mm = new MavenEntity();
mm.setDFile(absolutePath);
mm.setDGroupId(DgroupId);
mm.setDArtifactId(DartifactId);
mm.setDVersion(Dversion);
String script = getScript(mm);
System.out.println(script);
}
}
}
}
} else {
System.out.println("文件不存在!");
}
return;
}
public static String getScript(MavenEntity mavenEntity) {
String demoScript = "mvn deploy:deploy-file -DgroupId=com.junit -DartifactId=junit -Dversion=1.0.0 -Dpackaging=jar -Dfile=D:/repository/ojdbc-1.0.0.jar -Durl=http://192.168.5.128:8081/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty";
String DgroupId = mavenEntity.getDGroupId();
String DartifactId = mavenEntity.getDArtifactId();
String Dversion = mavenEntity.getDVersion();
String Dpackaging = "jar";
String Dfile = mavenEntity.getDFile();
String Durl = "http://192.168.5.128:8081/nexus/content/repositories/thirdparty";
String DrepositoryId = "thirdparty";
String script = "mvn deploy:deploy-file -DgroupId=" + DgroupId + " -DartifactId=" + DartifactId + " -Dversion=" + Dversion + " -Dpackaging=" + Dpackaging + " -Dfile=" + Dfile + " -Durl=" + Durl + " -DrepositoryId=" + DrepositoryId + "";
return script;
}
static class MavenEntity {
String DFile;
String DGroupId;
String DArtifactId;
String DVersion;
public String getDFile() {
return DFile;
}
public void setDFile(String DFile) {
this.DFile = DFile;
}
public String getDGroupId() {
return DGroupId;
}
public void setDGroupId(String DGroupId) {
this.DGroupId = DGroupId;
}
public String getDArtifactId() {
return DArtifactId;
}
public void setDArtifactId(String DArtifactId) {
this.DArtifactId = DArtifactId;
}
public String getDVersion() {
return DVersion;
}
public void setDVersion(String DVersion) {
this.DVersion = DVersion;
}
}
}
3.整个库上传
直接将整个目录拷贝至这个目录中
然后更新索引