Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This compiles the java source files using the newer javax.tools.JavaCompiler
- * as the other method is deprecated.
- *
- * @param srcDir The source directory.
- * @param binDir The build directory.
- * @param classPath The class path.
- * @return
- */
- public boolean compile(String srcDir, String binDir, String classPath) {
- boolean success = false;
- try {
- List<String> files = new LinkedList<String>();
- List<String> args = new LinkedList<String>();
- args.add("-cp");
- args.add(classPath.replaceAll("[:;]", System.getProperty("path.separator")));
- args.add("-d");
- args.add(homeDir + binDir);
- findJavaRecursive(files, new File(homeDir + srcDir));
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
- Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(files);
- success = compiler.getTask(null, fileManager, null, args, null, compilationUnits).call();
- fileManager.close();
- } catch (IOException ex) {
- return false;
- }
- return success;
- }
Advertisement
Add Comment
Please, Sign In to add comment