<tfoot id='XNYIp'></tfoot>
      <bdo id='XNYIp'></bdo><ul id='XNYIp'></ul>
    1. <i id='XNYIp'><tr id='XNYIp'><dt id='XNYIp'><q id='XNYIp'><span id='XNYIp'><b id='XNYIp'><form id='XNYIp'><ins id='XNYIp'></ins><ul id='XNYIp'></ul><sub id='XNYIp'></sub></form><legend id='XNYIp'></legend><bdo id='XNYIp'><pre id='XNYIp'><center id='XNYIp'></center></pre></bdo></b><th id='XNYIp'></th></span></q></dt></tr></i><div id='XNYIp'><tfoot id='XNYIp'></tfoot><dl id='XNYIp'><fieldset id='XNYIp'></fieldset></dl></div>

      <legend id='XNYIp'><style id='XNYIp'><dir id='XNYIp'><q id='XNYIp'></q></dir></style></legend>

      1. <small id='XNYIp'></small><noframes id='XNYIp'>

      2. 从自定义类加载器中使用 javax.tools.ToolProvider?

        时间:2023-10-14

              <tbody id='kL6hP'></tbody>
          • <tfoot id='kL6hP'></tfoot>
            • <bdo id='kL6hP'></bdo><ul id='kL6hP'></ul>
              <legend id='kL6hP'><style id='kL6hP'><dir id='kL6hP'><q id='kL6hP'></q></dir></style></legend>
              <i id='kL6hP'><tr id='kL6hP'><dt id='kL6hP'><q id='kL6hP'><span id='kL6hP'><b id='kL6hP'><form id='kL6hP'><ins id='kL6hP'></ins><ul id='kL6hP'></ul><sub id='kL6hP'></sub></form><legend id='kL6hP'></legend><bdo id='kL6hP'><pre id='kL6hP'><center id='kL6hP'></center></pre></bdo></b><th id='kL6hP'></th></span></q></dt></tr></i><div id='kL6hP'><tfoot id='kL6hP'></tfoot><dl id='kL6hP'><fieldset id='kL6hP'></fieldset></dl></div>

              <small id='kL6hP'></small><noframes id='kL6hP'>

                  本文介绍了从自定义类加载器中使用 javax.tools.ToolProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  似乎无法按照 Ant 或 Webstart 的要求使用自定义类加载器中的 javax.tools.ToolProvider:http://bugs.sun.com/view_bug.do?bug_id=6548428

                  It seems to be impossible to use javax.tools.ToolProvider from a custom classloader as required by Ant or Webstart: http://bugs.sun.com/view_bug.do?bug_id=6548428

                  javax.tools.ToolProvider.getSystemJavaCompiler()javax.tools.JavaCompiler 加载到 URLClassLoader 中,其父级是系统类加载器.API 似乎不允许用户指定父类加载器.

                  javax.tools.ToolProvider.getSystemJavaCompiler() loads javax.tools.JavaCompiler into a URLClassLoader whose parent is the system classloader. The API does not seem to allow users to specify a parent classloader.

                  如何使用自定义类加载器中的 javax.tools.JavaCompiler?

                  例如:

                  • Ant 加载 MyParserTask
                  • MyParserTask 解析 Java 源代码
                  • MyParserTask 由委托给系统类加载器的 AntClassLoader 加载
                  • javax.tools.JavaCompilerURLClassLoader 加载,委托给系统类加载器
                  • Ant loads MyParserTask
                  • MyParserTask parses Java source-code
                  • MyParserTask is loaded by AntClassLoader that delegates to the system classloader
                  • javax.tools.JavaCompiler is loaded by URLClassLoader thast delegates to the system classloader

                  稍后,MyParserTask 调用:

                  javax.tools.CompilationTask task = compiler.getTask(...);
                  com.sun.source.util.JavacTask javacTask = (com.sun.source.util.JavacTask) task;
                  javacTask.parse().next().accept(visitor, unused); // parsing happens here
                  

                  • 看到这两个类如何驻留在不同的类加载器上,MyParserTask 似乎没有办法与 JavacTask 交互而不会得到 ClassCastException错误.
                    • Seeing how the two classes reside on separate classloaders, there doesn't seem to be a way for MyParserTask to interact with JavacTask without getting ClassCastException errors.
                    • 有什么想法吗?

                      推荐答案

                      我遇到了完全相同的问题.我正在使用自定义 ant 任务来扫描 AST 以查找某些类型的方法调用.我的解决方案可能不适合您,而是自己实例化编译器,而不是使用 ToolProvider.

                      I had exactly the same problem. I'm using a custom ant task to scan the AST for certain kinds of method invocations. My solution, which may not be appropriate for you, was to instantiate the compiler myself instead of using the ToolProvider.

                      我换了

                      JavaCompiler 编译器 = ToolProvider.getSystemJavaCompiler();

                      JavaCompiler 编译器 = (JavaCompiler)Class.forName("com.sun.tools.javac.api.JavacTool").newInstance();

                      这当然不是面向未来或在所有环境中都是安全的,但它是一个取决于您的需求的选项.如果其他人在自定义 Ant 任务中使用 ToolProvider 有更好的方法,请分享.

                      This certainly isn't future proof or safe in all environments, but it is an option depending on your needs. If someone else has a better way around using ToolProvider in custom Ant tasks please share.

                      这篇关于从自定义类加载器中使用 javax.tools.ToolProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <small id='fHoYZ'></small><noframes id='fHoYZ'>

                    <tbody id='fHoYZ'></tbody>
                    <bdo id='fHoYZ'></bdo><ul id='fHoYZ'></ul>
                    <legend id='fHoYZ'><style id='fHoYZ'><dir id='fHoYZ'><q id='fHoYZ'></q></dir></style></legend>
                  • <i id='fHoYZ'><tr id='fHoYZ'><dt id='fHoYZ'><q id='fHoYZ'><span id='fHoYZ'><b id='fHoYZ'><form id='fHoYZ'><ins id='fHoYZ'></ins><ul id='fHoYZ'></ul><sub id='fHoYZ'></sub></form><legend id='fHoYZ'></legend><bdo id='fHoYZ'><pre id='fHoYZ'><center id='fHoYZ'></center></pre></bdo></b><th id='fHoYZ'></th></span></q></dt></tr></i><div id='fHoYZ'><tfoot id='fHoYZ'></tfoot><dl id='fHoYZ'><fieldset id='fHoYZ'></fieldset></dl></div>
                    <tfoot id='fHoYZ'></tfoot>