diff options
author | Deepak Bhole <[email protected]> | 2012-02-28 11:35:41 -0500 |
---|---|---|
committer | Deepak Bhole <[email protected]> | 2012-02-28 11:35:41 -0500 |
commit | f1cd5727f6e4fec7dea99c8f779e22d1f9a83e17 (patch) | |
tree | 532d4c0d2f04edf7a12384a4a7e5b703e62a7df4 /netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | |
parent | f7c2d6d53a4546b367fb8834b50a60edfc6dc7ff (diff) |
Added check for main class in jar manifest(s)
Diffstat (limited to 'netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java')
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index 290902a..1a1be71 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -593,6 +593,39 @@ public class JNLPClassLoader extends URLClassLoader { 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 @@ public class JNLPClassLoader extends URLClassLoader { } /** + * 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. * |