" public void run() {" +
" Hello hello = new Hello();" +
" System.out.println(hello.greeting());" +
" }" +
"}";
MemoryClassFactory factory = new MemoryClassFactoryImpl();
Map sourceMap = new HashMap();
sourceMap.put("test.Hello", helloSource);
sourceMap.put("test.main.Main", mainSource);
factory.setInput(sourceMap);
JavaCompiler compiler = new JavaCompilerImpl();
compiler.compile(new String[] {"test.main.Main"},
factory,
factory,
factory,
new JavaCompilerErrorHandler() {
public void handleError(String className,
int line,
int column,
Object errorMessage) {
String msg = className;
if (line > 0) {
msg += ": Line " + line;
}
if (column >= 0) {
msg += "." + column;
}
msg += ": ";
msg += errorMessage;
System.err.println(msg);
}
});
Class clazz = factory.loadClass("test.main.Main");
Runnable runner = (Runnable)clazz.newInstance();
runner.run();
}