byte[] javacCompile(String packageName,String className,String source){
  File dir=new File(COMPILE_DIR);
  if (packageName != null) {
    dir=new File(dir,packageName.replace('.','/'));
    FileUtils.createDirectories(dir.getAbsolutePath());
  }
  File javaFile=new File(dir,className + ".java");
  File classFile=new File(dir,className + ".class");
  try {
    OutputStream f=FileUtils.newOutputStream(javaFile.getAbsolutePath(),false);
    Writer out=IOUtils.getBufferedWriter(f);
    classFile.delete();
    out.write(source);
    out.close();
    if (JAVAC_SUN != null) {
      javacSun(javaFile);
    }
 else {
      javacProcess(javaFile);
    }
    byte[] data=new byte[(int)classFile.length()];
    DataInputStream in=new DataInputStream(new FileInputStream(classFile));
    in.readFully(data);
    in.close();
    return data;
  }
 catch (  Exception e) {
    throw DbException.convert(e);
  }
 finally {
    javaFile.delete();
    classFile.delete();
  }
}

byte [ ] javacCompile ( String packageName , String className , String source ) { File dir = new File ( COMPILE_DIR ) ; if ( packageName != null ) { dir = new File ( dir , packageName . replace ( '.' , '/' ) ) ; FileUtils . createDirectories ( dir . getAbsolutePath ( ) ) ; } File javaFile = new File ( dir , className + ".java" ) ; File classFile = new File ( dir , className + ".class" ) ; try { OutputStream f = FileUtils . newOutputStream ( javaFile . getAbsolutePath ( ) , false ) ; Writer out = IOUtils . getBufferedWriter ( f ) ; classFile . delete ( ) ; out . write ( source ) ; out . close ( ) ; if ( JAVAC_SUN != null ) { javacSun ( javaFile ) ; } else { javacProcess ( javaFile ) ; } byte [ ] data = new byte [ ( int ) classFile . length ( ) ] ; DataInputStream in = new DataInputStream ( new FileInputStream ( classFile ) ) ; in . readFully ( data ) ; in . close ( ) ; return data ; } catch ( Exception e ) { throw DbException . convert ( e ) ; } finally { javaFile . delete ( ) ; classFile . delete ( ) ; } }
compile the given class . this method tries to use the class " com . sun . tools . javac . main " if available . if not , it tries to run " javac " in a separate process .
