Search code examples
hyperlinkjavadoc

How to write javadoc links?


How do I write links into javadocs?

Currently, I have something like:

{@link java.lang.Math#sqrt(double) Math.sqrt}

to produce the text Math.sqrt that should link to the java.lang.Math.sqrt(double) API, however, all it does is produce the text, no link.


Solution

  • To get a link to something external to your code, you need use the -linkoffline option

    where the -linkoffline option has the format something like this (artificially wrapped):

    -linkoffline http://java.sun.com/javase/6/docs/api/
                 http://java.sun.com/javase/6/docs/api/
    

    This tells the JavaDoc tool where to find the link to the JavaDoc and for what packages to use that link. From the 2nd URL, it will append "package-list" to load the actual URL:

    http://java.sun.com/javase/6/docs/api/package-list

    which you can verify by loading it in a browser does contain the list of packages documented at that JavaDoc URL. This tells the JavaDoc tool that any @link references to anything in one of those packages should link to the provided URL.