-
点击右上角sign in登录按钮,登录到nexus中
-
登录后,会出现设置按钮,如图
-
点击设置按钮,点击左侧的system,点击API,即可打开restFul接口界面
-
点击打开 Components 组,找到 /v1/components 接口,打开
-
点击 “Try it out”,然后在 repository *required 的输入框中,输入仓库名称,仓库名称,来源于browse列表
点击 Execute执行,即可看到相应的下载连接
-
将上面的回参,下载到本地,点击图中的 download,即可下载回参 json 文件
-
将回参拉到底部,查看continuationToken 的值是否为 null,如下如
如果不为null,则表示还有下页,如果为null,则表示当前拉取的数据为全部
9. 如果数据有下页。则拿到continuationToken的值,填写到 请求的continuationToken中,继续执行,然后下载json文件,直到返回的continuationToken的值为null为止
- 编写java程序,下载json里面的所有jar以及pom到本地
a. 核心依赖
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
b. 核心代码
package com.mose;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DownloadJar {
private static final String initPath = "D:\\nexusd\\";
// private static final String filePath = "D:\\project-owner\\tools\\nexus-util\\src\\main\\resources\\product.json";
// 此处若有多个json文件,依次执行即可
private static final String filePath = "D:\\nexusd\\4.json";
// private static final String filePath = "/close/tmp/product.json";
public HashMap<String, Object> readJson() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
FileReader fileReader = new FileReader(filePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer sb = new StringBuffer();
String s = "";
while (StringUtils.isNotEmpty(s = bufferedReader.readLine())) {
sb.append(s.trim());
}
return objectMapper.readValue(sb.toString(), HashMap.class);
}
public void download() throws IOException {
HashMap<String, Object> stringStringHashMap = readJson();
List<Map> list = (List) stringStringHashMap.get("items");
for (Map map : list) {
List<Map> assets = (List<Map>) map.get("assets");
for (Map dMap : assets) {
String url = dMap.get("downloadUrl") + "";
String path = dMap.get("path") + "";
genFile(url, initPath + path);
}
}
}
private void genFile(final String urlStr, final String path) {
System.out.println(path);
try {
URL url = new URL(urlStr);
String tempFileName = path;
// 先创建文件夹
File t = new File(path);
t.getParentFile().mkdirs();
File temp = new File(tempFileName);
FileUtils.copyURLToFile(url, temp);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) throws IOException {
new DownloadJar().download();
}
}
-
运行java代码,即可下载所有jar包到本地
-
迁移
下载迁移工具
https://agent-install.oss-cn-hangzhou.aliyuncs.com/migrate-local-repo-tool.jar?file=migrate-local-repo-tool.jar执行迁移命令
java -jar migrate-local-repo-tool.jar -cd "D:/nexusd/" -t https://packages.aliyun.com/maven/repository/111 -u '********' -p '***'