天气:晴 风力:无风
tools.jar ---> javac
第一次遇到有项目里用到了tools.jar包,稍微研究下。
- tools.jar里的内容就是我们平时用到的一些工具类库,例如javac,javap,javah等工具类,bin目录的javac应该是一个封装的调用程序
-
- javac实现
- com.sun.tools.javac.Main main方法点用main包Main类的compile方法编译java文件
public static void main(String[] arg) throws Exception {
System.exit(compile(arg));
}
public static int compile(String[] arg) {
com.sun.tools.javac.main.Main arg0 = new com.sun.tools.javac.main.Main("javac");
return arg0.compile(arg).exitCode;
}
2.com.sun.tools.javac.main.Main
- compile方法层层调用
public Result compile(String[] arg0, String[] arg1, Context arg2,
List<JavaFileObject> arg3, Iterable<? extends Processor> arg4) {
//做一些参数的文件判断,日志输出环境等
//准备compile环境,加载内置插件
//准备编译类和编译参数
//编译,arg3, arg4都是空的对象
···
arg5.compile(arg3, this.classnames.toList(), arg4);
···
}
- JavaCompiler.compile()
···
this.delegateCompiler = this.processAnnotations(
this.enterTrees(this.stopIfError(CompileState.PARSE, this.parseFiles(arg0))), arg1);
this.delegateCompiler.compile2();
···
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> arg0, Queue<JavaFileObject> arg1) {
···
}
暂停睡觉~~~
网友评论