So I recently learned of the new JavaCompiler API available in JDK 1.6. This makes it very simple to compile a String
to a .class
file directly fr
The reason that there is no standard API to write bytecodes to a byte array is that compiling a single Java source file may result in multiple bytecode files. For example, any source file with nested / inner / anonymous classes will result in multiple bytecode files.
If you roll your own JavaFileManager, you will need to deal with this situation.