JavaCompiler from JDK 1.6: how to write class bytes directly to byte[] array?

后端 未结 3 366
灰色年华
灰色年华 2021-01-02 15:52

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

3条回答
  •  日久生厌
    2021-01-02 16:33

    Maybe you could create your own javax.tools.JavaFileManager implementing class where you would return your own implementation of javax.tools.FileObject which would then write it out to memory instead to disk. So for your subclass of javax.tools.FileObject Writer openWriter() throws IOException method you would return a java.io.StringWriter. All the methods should be converted to their String counterparts.

提交回复
热议问题