|
@ -9,6 +9,7 @@ import javax.tools.*;
|
|
|
import java.io.File;
|
|
|
import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
@ -38,13 +39,13 @@ public class CamelCompiler {
|
|
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
|
// 建立DiagnosticCollector对象
|
|
|
DiagnosticCollector diagnostics = new DiagnosticCollector();
|
|
|
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
|
|
|
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, Charset.forName("UTF-8"));
|
|
|
// 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
|
|
|
File file = genNewJava(filePath,packageName, oldClassName,newClassName, newCron);
|
|
|
if (file!=null){
|
|
|
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
|
|
|
// options命令行选项
|
|
|
Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
|
|
|
Iterable<String> options = Arrays.asList("-d",classPath,"-sourcepath", classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
|
|
|
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
|
|
|
|
|
|
// 编译源程序
|
|
@ -74,7 +75,7 @@ public class CamelCompiler {
|
|
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
|
// 建立DiagnosticCollector对象
|
|
|
DiagnosticCollector diagnostics = new DiagnosticCollector();
|
|
|
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
|
|
|
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, Charset.forName("UTF-8"));
|
|
|
// 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
|
|
|
File file = new File(filePath);
|
|
|
File toFIle = new File(newPath);
|
|
@ -138,7 +139,6 @@ public class CamelCompiler {
|
|
|
if (!fPath.exists()) fPath.mkdirs();
|
|
|
|
|
|
File f = new File(newPath);
|
|
|
|
|
|
FileWriter fw = new FileWriter(f);
|
|
|
fw.write(text);
|
|
|
fw.flush();
|