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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -