Is it possible for javax.tools.JavaCompiler to compile a file but return the bytecode into a byte[] and not actually creating a .class file?? My current code:
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler
.getStandardFileManager(diagnostics, null, null);
Iterable<? extends JavaFileObject> compilationUnit = fileManager
.getJavaFileObjectsFromFiles(Arrays.asList(fileToCompile));
JavaCompiler.CompilationTask task = compiler
.getTask(osw, fileManager, diagnostics, null, null, compilationUnit);
task.call()
fileToCompile.delete();
fileManager.close();
In the code above fileToCompile
is a File
. I also want to replace this File
by a byte[]
or a InputStream
of the .java file to compile. Thanks in advance