@Override
public byte[] getClassByteCode(final String className, final String sourcecode) throws CompileException, IOException,
ClassNotFoundException {
// Create one Java source file in memory, which will be compiled later.
JavaFileObject compilationUnit = getCompilationUnit(sourcecode);
//logger.debug("Compiling the following source code\n{}", sourcecode);
// Run the compiler.
try {
CompilationTask task = compiler.getTask(null, fileManager, listener, getOptions(), null, Collections.singleton(compilationUnit));
long n0 = System.nanoTime();
if(!task.call()){
throw new CompileException("Compilation failed", null);
}
long n1 = (System.nanoTime() - n0)/1000/1000;
} catch (RuntimeException rte) {
// Unwrap the compilation exception and throw it.
Throwable cause = rte.getCause();
if (cause != null) {
cause = cause.getCause();
if (cause instanceof CompileException) throw (CompileException) cause;
if (cause instanceof IOException) throw (IOException) cause;
}
throw rte;
}
JavaFileObject classFileObject = fileManager.getJavaFileForInput(StandardLocation.CLASS_OUTPUT, className, Kind.CLASS);
if (classFileObject == null) {
throw new ClassNotFoundException(className + ": Class file not created by compilation");
}