Search code examples
javadoc

How to generate external link to 3rd party classes with Javadoc


I'm trying to use links to 3rd party libraries in my Java class docs, however javadoc tool cannot generate a link.

/**
* A link to 3rd party lib class {@link dagger.Lazy}
*/
public class MyCLass {
    /**
     * main desc 
     */
    static public void main() {
        return;
    }
} 

Then run javadoc tool:

javadoc -link https://dagger.dev/api/2.0/ ./MyClass.java

javadoc creates docs for MyClass, but cannot generate a link to dagger.Lazy, see log below:

Loading source file .\MyClass.java...
Constructing Javadoc information...
Building index for all the packages and classes...
Building tree for all the packages and classes...
.\MyClass.java:2: error: reference not found
* A link to 3rd party lib class {@link dagger.Lazy}
                                       ^
Generating .\package-summary.html...
Generating .\package-tree.html...
Generating .\overview-tree.html...
Building index for all classes...
Generating .\allclasses-index.html...
Generating .\allpackages-index.html...
Generating .\index-all.html...
Generating .\search.html...
Generating .\index.html...
Generating .\help-doc.html...
1 error

I also tried to use @see tag, but javadoc also didn't generate a link, without an error message.

What am I doing wrong?


Solution

  • Finally I realized my mistake - docs don't provide a class list, but module and package list. If you want to link your docs with some external docs using class or method names, you need to specify a classpath to the jar file, similar to javac. This is how javadoc will know about classes.

    Here is the example:

    javadoc -cp ./dagger-2.0.2.jar -link https://dagger.dev/api/2.0/ ./MyClass.java
    

    Now javadoc knows about Dagger classes, and also knows where to link. {@link dagger.Lazy} will link to https://dagger.dev/api/2.0/dagger/Lazy.html