!636 !1000363 // class _x16 main { static Method findMainMethod(Class theClass) { for (Method method : theClass.getMethods()) if (method.getName().equals("main") && method.getParameterTypes().length == 1) return method; throw new RuntimeException("Method 'main' with 1 parameter not found in " + theClass.getName()); } psvm { String mainSrc = "return (String) o + \" \" + (String) o;"; String prelude = "public class main { public static Object main(Object o) throws Exception {\n"; String postlude = "\n}}"; String src = prelude + mainSrc + postlude; File srcDir = _x16.TempDirMaker_make(); File classesDir = _x16.TempDirMaker_make(); _x16.saveTextFile(new File(srcDir, "main.java").getPath(), src); List libraries = new ArrayList(); String javacOutput = _x16.compileJava(srcDir, libraries, classesDir); System.out.println(javacOutput); URL[] urls = {classesDir.toURI().toURL()}; // make class loader URLClassLoader classLoader = new URLClassLoader(urls); // load main class Class mainClass = classLoader.loadClass("main"); Method m = findMainMethod(mainClass); Object in = "helloinput"; Object out = m.invoke(null, in); System.out.println(in + " => " + out); } }