[RFC] netx: search for main method in superclasses of the main class

Deepak Bhole dbhole at redhat.com
Thu Aug 5 07:17:36 PDT 2010


* Omair Majid <omajid at redhat.com> [2010-08-05 09:55]:
> On 08/05/2010 07:30 AM, Dr Andrew John Hughes wrote:
> >On 17:46 Wed 04 Aug     , Omair Majid wrote:
> >>Hi,
> >>
> >>The attached patch makes netx search for the main method in the
> >>superclasses of the main class. This patch allows JOSM [1] to work with
> >>Netx.
> >>
> >>Some applications like JOSM declare a main class which does not contain
> >>a main method - the main method is declared in a superclass instead. The
> >>tar file attached contains a simple example of such an application. With
> >>the current version of netx, it throws an exception, saying that the
> >>main method can not be found. The attached patch moves some the method
> >>lookup code into a findMainMethod() which also loops through the
> >>superclasses looking for the main method if it is not found in the
> >>declared main class.
> >>
> >>Any comments or concerns?
> >>
> >>Cheers,
> >>Omair
> >>
> >>[1] http://josm.openstreetmap.de/download/josm.jnlp
> >>
> >
> >Using getMethod rather than getDeclaredMethod:
> >
> >http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#getMethod%28java.lang.String,%20java.lang.Class...%29
> >
> >would perform the looping over the superclasses and superinterfaces;
> >
> >'Let C be the class represented by this object:
> >
> >    1. C is searched for any matching methods. If no matching method is found, the algorithm of step 1 is invoked recursively on the superclass of C.
> >    2. If no method was found in step 1 above, the superinterfaces of C are searched for a matching method. If any such method is found, it is reflected.'
> >
> 
> Thanks, that makes the patch alot simpler :) Attaching the updated patch.
> 

Hah! :) Approved for commit into 1.7, 1.8 and HEAD.

Deepak

> Cheers,
> Omair

> 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	Thu Aug 05 09:53:20 2010 -0400
> @@ -441,7 +441,7 @@
>  
>              Class mainClass = app.getClassLoader().loadClass(mainName);
>  
> -            Method main = mainClass.getDeclaredMethod("main", new Class[] {String[].class} );
> +            Method main = mainClass.getMethod("main", new Class[] {String[].class} );
>              String args[] = file.getApplication().getArguments();
>              
>              SwingUtilities.invokeAndWait(new Runnable() {




More information about the distro-pkg-dev mailing list