Debugging of custom Java doclet

Source: Internet
Author: User

APIs are often provided at work. At this time, the interface documentation is very troublesome and maintained on the Wiki or elsewhere. However, after the code is modified, the Wiki may not be updated in time, it causes a lot of communication costs. Therefore, you want to generate interface documents directly through javadoc. I found the javadoc plug-in provided by Maven, but the native doclet cannot meet my requirements. Therefore, you need to define your own doclet. Let's take a look at the definition of doclet:

Doclet is a program written in the javatm programming language. It uses doclet API to specify the output content and format of the javadoc tool. By default, the javadoc tool uses the "standard" doclet provided by suntm to generate API documents in HTML format. However, you can use your own doclet to customize javadoc output based on your preferences. Users can use doclet
You can also modify the standard doclet to suit your needs.
The basic steps for creating and using your own doclet are as follows:

1. Write a Java program used to construct doclet. To use the doclet API, this program should import com. Sun. javadoc .*. The program entry point is a class with the public static Boolean start method, which uses rootdoc as a parameter.
2. Compile doclet. You can use Java Development Kit's compiler javac to compile it.
3. Run the javadoc tool with the-doclet <yourdoclet> Option to generate the output specified by doclet.

The doclet API file is in the LIB/tools. jar file of JDK software. When compiling doclet and using custom doclet, tools. jar must be in the class path. Therefore, you can use the-classpath option for javac and javadoc.

The doclet needs to use tools. Jar. When using ide such as idea, add the path of tools. jar to JDK classpath in project setting. However, this debugging is too troublesome. According to the information on the Internet, you can only compile your doclet on the outside.
And then use javadoc-doclet to specify the compiled doclet. However, in this case, you cannot debug the doclet program and find the online documents and add your own time.

public class APIDoclet {    public static boolean start(RootDoc root) {        ClassDoc[] classes = root.classes();        for (int i = 0; i < classes.length; ++i) {            System.out.println(classes[i]);        }        return true;    }    public static void main(String[] args) {        String[] docArgs = new String[]{"-doclet", APIDoclet.class.getName(), System.getProperty("user.dir") + "/src/main/java/" + "com/hz/yk/concurrent/aqs/BooleanMutex.java"};        com.sun.tools.javadoc.Main.execute(docArgs);    }}

Haha, now we can break the breakpoint.

Attached doclet documents:

Http://dadi520.iteye.com/blog/545897

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.