[英]How can I debug a Doclet in Eclipse?
I am creating a custom doclet that I want to run in my Maven build with the Javadoc plugin, but right now I'd like to test / debug the Doclet in Eclipse. 我正在创建一个自定义doclet,我希望在我的Maven构建中使用Javadoc插件运行,但是现在我想在Eclipse中测试/调试Doclet。 How can I do that?
我怎样才能做到这一点?
Do I have to invoke javadoc programmatically? 我是否必须以编程方式调用javadoc? And how?
如何?
you can simply create a main method in your doclet and call (example, see full cmdling reference): 您只需在doclet中调用main方法并调用(例如,请参阅完整的cmdling参考):
public class MyDoclet extends Doclet {
public static void main(String[] args) {
com.sun.tools.javadoc.Main.execute("-doclet " + MyDoclet.class.getName());
}
}
That also works with the debugger. 这也适用于调试器。
You might also have to add the -classpath parameter containing all jar dependencies needed to parse the actual code. 您可能还需要添加-classpath参数,该参数包含解析实际代码所需的所有jar依赖项。
If you are running JDK v1.8, you may need to use the following code snippet: 如果您运行的是JDK v1.8,则可能需要使用以下代码段:
Main.execute(docletFqcn.getClass().getClassLoader(), "-doclet", docletFqcn, javaSourceFilePath);
where docletFqcn
is the fully qualified class name of your Doclet class and javaSourceFilePath
the location of the Java file to process. 其中
docletFqcn
是Doclet类的完全限定类名,而javaSourceFilePath
是要处理的Java文件的位置。
I got error message with @Jan answer 我收到了@Jan回答的错误信息
Error:(13, 35) java: reference to execute is ambiguous
both method execute(java.lang.String...) in com.sun.tools.javadoc.Main and method execute(java.lang.String,java.lang.String...) in com.sun.tools.javadoc.Main match
After change to these code and it work well 更改为这些代码后,它运行良好
com.sun.tools.javadoc.Main.execute(new String[]{
"-doclet", CustomDoclet.class.getName(),
"path/to/src/XXX.java"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.