I've run the above code in Mac OS Java 7. None of them works. So i wrote one
https://github.com/trung/InMemoryJavaCompiler
StringBuffer sourceCode = new StringBuffer();
sourceCode.append("package org.mdkt;
");
sourceCode.append("public class HelloClass {
");
sourceCode.append(" public String hello() { return "hello"; }");
sourceCode.append("}");
Class<?> helloClass = InMemoryJavaCompiler.compile("org.mdkt.HelloClass", sourceCode.toString());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…