File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .kimmking .kmq ;
2+
3+ import lombok .SneakyThrows ;
4+
5+ import java .io .File ;
6+ import java .lang .reflect .Method ;
7+ import java .net .URL ;
8+ import java .net .URLClassLoader ;
9+
10+ public class TestAddUrl {
11+
12+ @ SneakyThrows
13+ public static void main (String [] args ) {
14+ URLClassLoader classLoader = (URLClassLoader ) TestAddUrl .class .getClassLoader ();
15+ String dir = "/Users/kimmking/Downloads/Hello" ;
16+ Method method = URLClassLoader .class .getDeclaredMethod ("addURL" , URL .class );
17+ method .setAccessible (true );
18+ method .invoke (classLoader , new File (dir ).toURL ());
19+
20+ Class klass = Class .forName ("Hello" ,true , classLoader );
21+ Object obj = klass .newInstance ();
22+ Method hello = klass .getDeclaredMethod ("hello" );
23+ hello .invoke (obj );
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments