Guest User

jdk shit

a guest
Apr 14th, 2010
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.     /**
  2.      * This compiles the java source files using the newer javax.tools.JavaCompiler
  3.      * as the other method is deprecated.
  4.      *
  5.      * @param srcDir The source directory.
  6.      * @param binDir The build directory.
  7.      * @param classPath The class path.
  8.      * @return
  9.      */
  10.     public boolean compile(String srcDir, String binDir, String classPath) {
  11.         boolean success = false;
  12.         try {
  13.  
  14.             List<String> files = new LinkedList<String>();
  15.             List<String> args = new LinkedList<String>();
  16.             args.add("-cp");
  17.             args.add(classPath.replaceAll("[:;]", System.getProperty("path.separator")));
  18.             args.add("-d");
  19.             args.add(homeDir + binDir);
  20.             findJavaRecursive(files, new File(homeDir + srcDir));
  21.             JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  22.             StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
  23.             Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(files);
  24.             success = compiler.getTask(null, fileManager, null, args, null, compilationUnits).call();
  25.             fileManager.close();
  26.         } catch (IOException ex) {
  27.             return false;
  28.         }
  29.         return success;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment