Skip to content

Instantly share code, notes, and snippets.

@nokok
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nokok/c6af486d88c769b8180d to your computer and use it in GitHub Desktop.
Save nokok/c6af486d88c769b8180d to your computer and use it in GitHub Desktop.
import java.io.IOException;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
public class CreateHappyNewYear {
public static void main(String[] args) throws IOException, CannotCompileException {
ClassPool classPool = ClassPool.getDefault();
CtClass happyNewYearClazz = classPool.makeClass("HappyNewYear");
CtMethod method = CtNewMethod.make("public static void main(String[] args){"+
"System.out.println(\"Happy New Year!\");" +
"}", happyNewYearClazz);
happyNewYearClazz.addMethod(method);
happyNewYearClazz.writeFile(".");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment