-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrariesDownloader.java
More file actions
30 lines (28 loc) · 1.16 KB
/
LibrariesDownloader.java
File metadata and controls
30 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ...;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class LibrariesDownloader {
public void downloadLib(String group, String name, String version) {
try {
File libsDir = new File("libraries/" + group + "/" + name + "/" + version);
if (!libsDir.exists()) libsDir.mkdirs();
File jarFile = new File(libsDir, name + "-" + version + ".jar");
if (jarFile.exists()) return;
String url = "https://repo1.maven.org/maven2/" +
group.replace(".", "/") + "/" +
name + "/" +
version + "/" +
name + "-" + version + ".jar";
System.out.println("[TestPlugin] Downloading " + name + "...");
try (InputStream in = new URL(url).openStream()) {
Files.copy(in, jarFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
System.out.println("[TestPlugin] Installed " + name + ".");
} catch (Exception e) {
e.printStackTrace();
}
}
}