How to write javadoc links?

How to write links in javadocs?

I currently have something like:

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

to create Math.sqrt text that should reference the java.lang.Math.sqrt(double) API, however all it does is text without a link.

+42
hyperlink javadoc
Mar 31 '09 at 2:11
source share
3 answers

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

where the -linkoffline option has a format similar to 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 JavaDoc link and which packages to use this link. From the second URL, it will add a โ€œpackage listโ€ to load the actual URL:

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

which you can verify by downloading it in a browser, contains a list of packages registered at this JavaDoc URL. This tells the JavaDoc utility that any @link links to anything in one of these packages should link to the provided URL.

+17
Mar 31 '09 at 3:53
source share

My answer is very much given by Eddie, but his exact code does not work for me (or at least when using the version of javadoc that comes with Java 1.6)

If I do this:

  javadoc -linkoffline http://java.sun.com/javase/6/docs/api/ http://java.sun.com/javase/6/docs/api/package-list -public FileName.java 

then javadoc complains:

  javadoc: warning - Error fetching URL: http://java.sun.com/javase/6/docs/api/package-list/package-list 

If, on the other hand, I:

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

Then it works, and my links are filled in the way I want them to be.

Also, my link is not distorted. The text {@link java.lang.Math#sqrt(double) Math.sqrt} creates the link text Math.sqrt instead of the standard Math.sqrt(double) .

+20
Mar 31 '09 at 4:36
source share

This document may help, remember that for @link you need to use the URL for the document you are linking to.

-one
Mar 31 '09 at 2:46
source share



All Articles