diff -r 9da4f50c13c0 netx/net/sourceforge/jnlp/Launcher.java --- a/netx/net/sourceforge/jnlp/Launcher.java Wed Aug 04 00:46:09 2010 +0100 +++ b/netx/net/sourceforge/jnlp/Launcher.java Wed Aug 04 17:37:06 2010 -0400 @@ -20,6 +20,7 @@ import java.applet.Applet; import java.awt.Container; import java.io.File; +import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.ThreadMXBean; import java.lang.reflect.Method; @@ -420,28 +421,7 @@ ApplicationInstance app = createApplication(file); app.initialize(); - String mainName = file.getApplication().getMainClass(); - - // When the application-desc field is empty, we should take a - // look at the main jar for the main class. - if (mainName == null) { - JARDesc mainJarDesc = file.getResources().getMainJAR(); - File f = CacheUtil.getCacheFile(mainJarDesc.getLocation(), null); - if (f != null) { - JarFile mainJar = new JarFile(f); - mainName = mainJar.getManifest(). - getMainAttributes().getValue("Main-Class"); - } - } - - if (mainName == null) - throw launchError(new LaunchException(file, null, - R("LSFatal"), R("LCClient"), R("LCantDetermineMainClass") , - R("LCantDetermineMainClassInfo"))); - - Class mainClass = app.getClassLoader().loadClass(mainName); - - Method main = mainClass.getDeclaredMethod("main", new Class[] {String[].class} ); + Method main = findMainMethod(file, app); String args[] = file.getApplication().getArguments(); SwingUtilities.invokeAndWait(new Runnable() { @@ -450,7 +430,7 @@ }); setContextClassLoaderForAllThreads(app.getThreadGroup(), app.getClassLoader()); - + if (splashScreen != null) { if (splashScreen.isSplashScreenValid()) { splashScreen.setVisible(false); @@ -470,6 +450,47 @@ } } + private Method findMainMethod(JNLPFile file, ApplicationInstance app) throws IOException, + LaunchException, ClassNotFoundException, NoSuchMethodException { + String mainName = file.getApplication().getMainClass(); + + // When the application-desc field is empty, we should take a + // look at the main jar for the main class. + if (mainName == null) { + JARDesc mainJarDesc = file.getResources().getMainJAR(); + File f = CacheUtil.getCacheFile(mainJarDesc.getLocation(), null); + if (f != null) { + JarFile mainJar = new JarFile(f); + mainName = mainJar.getManifest().getMainAttributes().getValue("Main-Class"); + } + } + + if (mainName == null) + throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), + R("LCantDetermineMainClass"), R("LCantDetermineMainClassInfo"))); + + Class<?> mainClass = app.getClassLoader().loadClass(mainName); + + Method main = null; + + while (main == null) { + try { + main = mainClass.getDeclaredMethod("main", new Class[] { String[].class }); + return main; + } catch (NoSuchMethodException e) { + // if we can not find the main method in the main class, try searching in the + // superclass of main + mainClass = mainClass.getSuperclass(); + if (mainClass == null) { + throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), + R("LCantDetermineMainClass"), R("LCantDetermineMainClassInfo"))); + } + } + } + + return main; + } + /** * Set the classloader as the context classloader for all threads in * the given threadgroup. This is required to make some applications