I need to compile java files which have dependencies that only exist as class files which have been loaded by the JVM doing the compilation. I am using the javax.tool JavaCompiler somewhat as described here: How do I programmatically compile and instantiate a Java class?
Additionally, I am using a StandardJavaFileManager to specify to the compiler my local classpath and the java files I am compiling.
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
...
compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
The the dependencies that are required have been loaded by a custom system class loader, and for security reasons cannot be written to disc to be supplied to the compiler's classpath.
Is there a way to get the JavaCompiler returned by ToolProvider.getSystemJavaCompiler() from the standard oracle JDK to use the class files which have been loaded by my custom class loader without writing them to disc? I'm also open to extending JavaCompiler or JavaFileManager as needed.
The only option I have come up with so far would be to use reflection to create dependencies as stubbed java files on disc, compile them, and provide them to the JavaCompiler. I don't care for this option as it seems cumbersome, and difficult as the dependencies are quite complex.
I've seen these questions:
Compile code fully in memory with javax.tools.JavaCompiler
How do I use JDK6 ToolProvider and JavaCompiler with the context classloader?
However, these solutions handle dynamic compilation, but do not seem to address the memory only dependency issue.