六号线晚报0604

天气:晴 风力:无风

tools.jar ---> javac

第一次遇到有项目里用到了tools.jar包,稍微研究下。

  • tools.jar里的内容就是我们平时用到的一些工具类库,例如javac,javap,javah等工具类,bin目录的javac应该是一个封装的调用程序
  • javac实现
  1. 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) {
     ···
}

暂停睡觉~~~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容