ぬるぽ

import java.lang.reflect.*;

public class NullPo {
    public static void main(String[] args) {
	if (args.length == 0) {
	    System.out.println("usage:java NullPo app-class-name app-args...");
	    System.exit(1);
	}
	try {
	    Class clazz = Class.forName(args[0]);
	    Class[] types = { args.getClass() };
	    Method method = clazz.getMethod("main", types);
	    String[] argz = new String[args.length - 1];
	    System.arraycopy(args, 1, argz, 0, argz.length);
	    Object arglist[] = { argz };
	    try {
		method.invoke(null, arglist);
	    } catch (IllegalAccessException e) {
		System.err.println("main() method is not public.");
	    } catch (IllegalArgumentException e) {
		e.printStackTrace();
	    } catch (InvocationTargetException e) {
		throw e.getCause();
	    }
	} catch (NoSuchMethodException e) {
	    System.err.println("the class has no main() method.");
	} catch (ClassNotFoundException e) {
	    System.err.println("no class found.");
	} catch (NullPointerException e) {
	    System.err.println("\uff76\uff9e\uff6f");
	    e.printStackTrace();
	} catch (Throwable e) {
	    e.printStackTrace();
	}
    }
}

意外と面倒。InvocationTargetException のあたりとか。