# HG changeset patch # User Deepak Bhole # Date 1330446941 18000 # Node ID e21f13506c3c7258165222870747868b030ae449 # Parent d3b97728550a615433a79116f6ff006c1c60a60e Added check for main class in jar manifest(s) diff -r d3b97728550a -r e21f13506c3c ChangeLog --- a/ChangeLog Tue Feb 28 10:05:57 2012 -0500 +++ b/ChangeLog Tue Feb 28 11:35:41 2012 -0500 @@ -1,3 +1,10 @@ +2012-02-28 Deepak Bhole + + * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java + (checkForMain): Also check manifest file of main jar. + (getMainClassName): New method. Looks in a jar manifest to see if there is + a Main-Class specified. + 2012-02-28 Deepak Bhole * plugin/icedteanp/IcedTeaPluginRequestProcessor.cc diff -r d3b97728550a -r e21f13506c3c netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Feb 28 10:05:57 2012 -0500 +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Feb 28 11:35:41 2012 -0500 @@ -593,6 +593,39 @@ mainClass = ad.getMainClass(); } else return; + + // The main class may be specified in the manifest + + // Check main jar + if (mainClass == null) { + JARDesc mainJarDesc = file.getResources().getMainJAR(); + mainClass = getMainClassName(mainJarDesc.getLocation()); + } + + // Check first jar + if (mainClass == null) { + JARDesc firstJarDesc = jars.get(0); + mainClass = getMainClassName(firstJarDesc.getLocation()); + } + + // Still not found? Iterate and set if only 1 was found + if (mainClass == null) { + + for (JARDesc jarDesc: jars) { + String mainClassInThisJar = getMainClassName(jarDesc.getLocation()); + + if (mainClassInThisJar != null) { + + if (mainClass == null) { // first main class + mainClass = mainClassInThisJar; + } else { // There is more than one main class. Set to null and break. + mainClass = null; + break; + } + } + } + } + String desiredJarEntryName = mainClass + ".class"; for (int i = 0; i < jars.size(); i++) { @@ -630,6 +663,30 @@ } /** + * Gets the name of the main method if specified in the manifest + * + * @param location The JAR location + * @return the main class name, null if there isn't one of if there was an error + */ + private String getMainClassName(URL location) { + + String mainClass = null; + File f = tracker.getCacheFile(location); + + if( f != null) { + try { + JarFile mainJar = new JarFile(f); + mainClass = mainJar.getManifest(). + getMainAttributes().getValue("Main-Class"); + } catch (IOException ioe) { + mainClass = null; + } + } + + return mainClass; + } + + /** * Is called by checkForMain() to check if the jar file is signed and if it * contains a signed JNLP file. *