-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaintest.java
More file actions
52 lines (44 loc) · 1.71 KB
/
Maintest.java
File metadata and controls
52 lines (44 loc) · 1.71 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
/**
* @author :chenxin
* @date :Created in 2020/3/28 12:20
* @description:
* @modified By:
* @version: $
*/
public class Maintest {
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
final URL resource = Maintest.class.getResource("");
System.out.println(resource);
int offset = Maintest.class.getResource("/").getPath().length();
Queue<File> files = new LinkedList<>();
files.add(new File(resource.getFile()));
List<Object> beans = new ArrayList<>();
while (!files.isEmpty()) {
File tmp = files.poll();
for (File f : tmp.listFiles()) {
if (f.isDirectory()) {
files.add(f);
} else {
if (f.getName().endsWith(".class")) {
String clsName = f.toURI().toURL().getPath().substring(offset).replaceAll("/", ".").replace(".class", "");
System.out.println(clsName);
final Class<?> aClass = Maintest.class.getClassLoader().loadClass(clsName);
if (!aClass.isInterface()) {
beans.add(aClass.getConstructor().newInstance());
}
}
}
}
}
System.out.println(offset);
System.out.println();
}
}