public Map<String,byte[]> compile(String fileName,String source) throws IOException {
  try (MemoryJavaFileManager manager=new MemoryJavaFileManager(stdManager)){
    JavaFileObject javaFileObject=manager.makeStringSource(fileName,source);
    CompilationTask task=compiler.getTask(null,manager,null,null,null,Arrays.asList(javaFileObject));
    Boolean result=task.call();
    if (result == null || !result.booleanValue()) {
      throw new RuntimeException("Compilation failed.");
    }
    return manager.getClassBytes();
  }
 }

public Map < String , byte [ ] > compile ( String fileName , String source ) throws IOException { try ( MemoryJavaFileManager manager = new MemoryJavaFileManager ( stdManager ) ) { JavaFileObject javaFileObject = manager . makeStringSource ( fileName , source ) ; CompilationTask task = compiler . getTask ( null , manager , null , null , null , Arrays . asList ( javaFileObject ) ) ; Boolean result = task . call ( ) ; if ( result == null || ! result . booleanValue ( ) ) { throw new RuntimeException ( "Compilation failed." ) ; } return manager . getClassBytes ( ) ; } }
compile a java source file in memory .
