forked from JavaCourse00/JavaCourseCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAddUrl.java
More file actions
22 lines (17 loc) · 723 Bytes
/
TestAddUrl.java
File metadata and controls
22 lines (17 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
public class TestAddUrl {
public static void main(String[] args) throws Exception {
URLClassLoader classLoader = (URLClassLoader) TestAddUrl.class.getClassLoader();
String dir = "/Users/kimmking/Downloads/Hello";
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(classLoader, new File(dir).toURL());
Class klass = Class.forName("Hello",true, classLoader);
Object obj = klass.newInstance();
Method hello = klass.getDeclaredMethod("hello");
hello.invoke(obj);
}
}