How can I debug a Doclet in Eclipse?

最后都变了- 提交于 2019-12-06 17:04:12

问题


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. How can I do that?

Do I have to invoke javadoc programmatically? And how?


回答1:


you can simply create a main method in your doclet and call (example, see full cmdling reference):

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.




回答2:


If you are running JDK v1.8, you may need to use the following code snippet:

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.




回答3:


I got error message with @Jan answer

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"
        });


来源:https://stackoverflow.com/questions/5909069/how-can-i-debug-a-doclet-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!