3

クラスパス上にない場合、実行時にJavaライブラリ(.jarファイル)をロードする方法はありますか?

4

1 に答える 1

6
URLClassLoader child = new URLClassLoader (myJar.toURL(), this.getClass().getClassLoader());
Class classToLoad = Class.forName ("com.MyClass", true, child);
Method method = classToLoad.getDeclaredMethod ("myMethod");
Object instance = classToLoad.newInstance ();
Object result = method.invoke (instance);

ソース:実行時に Jar を動的にロードするにはどうすればよいですか?

于 2010-11-06T06:01:39.133 に答える