JavaCC: I wish to generate java classes from dynamically generated jj files and to compile them at runtime

javajavaccruntime

I am refactoring a project which uses javaCC to create a proprietary language parser during compile time. Due to the fact that different variations of languages can exist at the same time, it has been decided to dynamically generate the java source code from the jj files during runtime, to then compile the java files into class files and load them.

In order to do so more efficiently I would like to generate the java files in memory to some stream I suppose. JavaCC's API Javadoc is not too accessible :).

How best to progress?

Best Answer

You're probably better off amending your build process as kdgregory suggests. But, this article describes how to create a new class loader that compiles bits of Java code on the fly using the compiler API. It should be fairly easy to modify it to read from files rather than strings.

Related Topic