分类:
2008-09-10 10:05:55
01 package compile;
02 import java.util.Date;
03 public class Target {
04 public void doSomething(){
05 Date date = new Date(10, 3, 3);
// 这个构造函数被标记为deprecated, 编译时会
// 向错误输出输出信息。
06 System.out.println("Doing...");
07 }
08 }
09 package compile;
10 import javax.tools.*;
11 import java.io.FileOutputStream;
12 public class Compiler {
13 public static void main(String[] args) throws Exception{
14 String fullQuanlifiedFileName = "compile" + java.io.File.separator +
"Target.java";
15 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
16 FileOutputStream err = new FileOutputStream("err.txt");
17 int compilationResult = compiler.run(null, null, err, fullQuanlifiedFileName);
18 if(compilationResult == 0){
19 System.out.println("Done");
20 } else {
21 System.out.println("Fail");
22 }
23 }
24 }