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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With