Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Do I have to invoke javadoc programmatically? And how?

like image 770
Sean Patrick Floyd Avatar asked May 06 '11 08:05

Sean Patrick Floyd


People also ask

How do I debug a program in eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.

How do I debug a .class file in eclipse?

There are two ways to debug a class file. The first way is to set the decompiler preference, and to realign the line number. The second way is to check the debug mode in the decompiler menu bar. When your Eclipse workspace is in debug perspective, the debug mode becomes the default.


2 Answers

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.

like image 168
Jan Avatar answered Oct 01 '22 14:10

Jan


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.

like image 31
Édouard Mercier Avatar answered Oct 01 '22 13:10

Édouard Mercier