java - How should I load Jars dynamically at runtime? -
why hard in java? if want have kind of module system need able load jars dynamically. i'm told there's way of doing writing own classloader
, that's lot of work should (in mind @ least) easy calling method jar file argument.
any suggestions simple code this?
the reason it's hard security. classloaders meant immutable; shouldn't able willy-nilly add classes @ runtime. i'm surprised works system classloader. here's how making own child classloader:
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);
painful, there is.
Comments
Post a Comment