Java reflection invoking main method of jar sometimes throws ClassNotFoundException? -
i'm invoking jar file using reflection mainmethod.invoke(null, new object[] { passargs });
(basic stuff). works jar files, 1 maintain getting classnotfoundexception
. it's erroring out on first line of code in external jar creating new object defined in jar (although other classes load own jar-classes fine). since error occuring on first line of jar's main method, don't think it's using custom classloaders.
any ideas cause classnotfoundexception when calling main method of jar? this works many other complex jars. 1 of them isn't working, , i'm wondering cause. works fine when executed individually java -jar
//my jar jarfile jar = new jarfile(load); attributes attributes = jar.getmanifest().getmainattributes(); string mainclass = attributes.getvalue("main-class"); urlclassloader cl = new urlclassloader(new url[] { new file(load).touri().tourl() }, classloader.getsystemclassloader()); class main = cl.loadclass(mainclass); system.out.println("main class: " + mainclass); method mainmethod = main.getdeclaredmethod("main", new class[] { string[].class }); mainmethod.invoke(null, new object[] { new string[0] });
it throws exception on line (other jar - 1 beingness invoked)
public static void main(string[] args) throws exception { loadingscreen ls = new loadingscreen();
exception:
exception in thread "main" java.lang.noclassdeffounderror: org/spoutcraft/launcher/gui/loadingscreen @ org.spoutcraft.launcher.main.main(main.java:106) @ com.mineshaftersquared.mineshaftersquaredgui.wrapjar(driver.java:110) @ com.mineshaftersquared.resources.serverproxy.main(serverproxy.java:71) caused by: java.lang.classnotfoundexception: org.spoutcraft.launcher.gui.loadingscreen @ java.net.urlclassloader$1.run(urlclassloader.java:202) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:190) @ java.lang.classloader.loadclass(classloader.java:306) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:301) @ java.lang.classloader.loadclass(classloader.java:247) ... 3 more
java reflection classloader main classnotfoundexception
No comments:
Post a Comment