-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJarLoader.java
executable file
·47 lines (38 loc) · 1.49 KB
/
JarLoader.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.*;
import java.net.*;
import java.util.jar.*;
public class JarLoader {
public static void main(String[] args) throws FileNotFoundException, IOException {
String jarName = "c:/temp/temp.jar"; // çàìåíèòü íà ñâîé
URLClassLoader urlLoader = getURLClassLoader(new URL("file", null, jarName));
JarInputStream jis = new JarInputStream(new FileInputStream(jarName));
JarEntry entry = jis.getNextJarEntry();
int loadedCount = 0, totalCount = 0;
while (entry != null) {
String name = entry.getName();
if (name.endsWith(".class")) {
totalCount++;
name = name.substring(0, name.length() - 6);
name = name.replace('/', '.');
System.out.print("> " + name);
try {
urlLoader.loadClass(name);
System.out.println("\t- loaded");
loadedCount++;
} catch (Throwable e) {
System.out.println("\t- not loaded");
System.out.println("\t " + e.getClass().getName() + ": " + e.getMessage());
}
}
entry = jis.getNextJarEntry();
}
System.out.println("\n---------------------");
System.out.println("Summary:");
System.out.println("\tLoaded:\t" + loadedCount);
System.out.println("\tFailed:\t" + (totalCount - loadedCount));
System.out.println("\tTotal:\t" + totalCount);
}
private static URLClassLoader getURLClassLoader(URL jarURL) {
return new URLClassLoader(new URL[]{jarURL});
}
}