Skip to content

Commit

Permalink
update TestAddUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmking committed Jan 21, 2021
1 parent ee52288 commit bf86c46
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 01jvm/TestAddUrl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.kimmking.kmq;

import lombok.SneakyThrows;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class TestAddUrl {

@SneakyThrows
public static void main(String[] args) {
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);
}

}

0 comments on commit bf86c46

Please sign in to comment.