changeset 855:07c44f5d2c52

2008-05-07 Joshua Sumali <jsumali@redhat.com> * rt/net/sourceforge/jnlp/Launcher.java: Check main jar for main class in case main class isn't specified in the jnlp file. * rt/net/sourceforge/jnlp/resources/Messages.properties: Add main class error messages.
author Joshua Sumali <jsumali@redhat.com>
date Wed, 07 May 2008 13:31:36 -0400
parents 1f85b520d105
children d86e9eb1fa7d
files ChangeLog rt/net/sourceforge/jnlp/Launcher.java rt/net/sourceforge/jnlp/resources/Messages.properties
diffstat 3 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed May 07 10:42:42 2008 -0400
+++ b/ChangeLog	Wed May 07 13:31:36 2008 -0400
@@ -1,3 +1,10 @@
+2008-05-07  Joshua Sumali  <jsumali@redhat.com>
+
+	* rt/net/sourceforge/jnlp/Launcher.java: Check main jar for main class in
+	case main class isn't specified in the jnlp file.
+	* rt/net/sourceforge/jnlp/resources/Messages.properties: Add main class 
+	error messages.
+
 2008-05-07  Joshua Sumali  <jsumali@redhat.com>
 
 	* rt/net/sourceforge/jnlp/cache/ResourceTracker.java: Close URL
--- a/rt/net/sourceforge/jnlp/Launcher.java	Wed May 07 10:42:42 2008 -0400
+++ b/rt/net/sourceforge/jnlp/Launcher.java	Wed May 07 13:31:36 2008 -0400
@@ -21,6 +21,7 @@
 import java.awt.Container;
 import java.io.*;
 import java.net.*;
+import java.util.jar.JarFile;
 import java.lang.reflect.*;
 
 import net.sourceforge.jnlp.cache.*;
@@ -317,6 +318,24 @@
             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} );
--- a/rt/net/sourceforge/jnlp/resources/Messages.properties	Wed May 07 10:42:42 2008 -0400
+++ b/rt/net/sourceforge/jnlp/resources/Messages.properties	Wed May 07 13:31:36 2008 -0400
@@ -48,6 +48,8 @@
 LInitApplicationInfo=
 LNotLaunchable=Not a launchable JNLP file.
 LNotLaunchableInfo=File must be a JNLP application, applet, or installer type.
+LCantDetermineMainClass=Unknown Main-Class.
+LCantDetermineMainClassInfo=Could not determine the main class for this application.
 
 JNotApplet=File is not an applet.
 JNotApplication=File is not an application.