See Oracle's Tutorial on Writing Java Doc Comments and the javadoc programmers guide (includes a link to the javadoc tool reference).
C:\Temp>mkdir docs
C:\Temp>notepad Greeter.java
C:\Temp>notepad GreeterApp.java
The following javadoc command must be entered
as a single line, even if it wraps as shown here:
C:\Temp>javadoc -d docs -private -author -version -noqualifi
er java.* -link http://docs.oracle.com/javase/8/docs/api/ *.java
Loading source file Greeter.java...
Loading source file GreeterApp.java...
Constructing Javadoc information...
Standard Doclet version 1.8.0_25
Building tree for all the packages and classes...
Generating docs\Greeter.html...
Generating docs\GreeterApp.html...
Generating docs\package-frame.html...
Generating docs\package-summary.html...
Generating docs\package-tree.html...
Generating docs\constant-values.html...
Building index for all the packages and classes...
Generating docs\overview-tree.html...
Generating docs\index-all.html...
Generating docs\deprecated-list.html...
Building index for all classes...
Generating docs\allclasses-frame.html...
Generating docs\allclasses-noframe.html...
Generating docs\index.html...
Generating docs\help-doc.html...
C:\Temp>
|
At this point, you can point your web browser to the generated documentation at ...\docs\index.html. |
Make sure you use the correct URL for the current version of
Java; here I used the URL for Java 8.
Note in this example, only some classes were documented.
To document a package, list the package name
on the command line instead of
“*.java
”.
(You can do both.)
Although not shown in this example, you can also have doc comments on a
package itself.
Simply create the file “package-info.java
” in
your package, that contains a doc comment and the package
statement, only.
It should look something like this:
/** My package overview sentence goes here. * Description of the package, that will show in the HTML * for the package as a whole. * @see <a href="http://wpollock.com/Java/PkgDemo.htm">Package Demo</a> */ package mypackagename;
/** Displays a custom greeting message. * Greeter objects have a <code>greet<code> method that takes a name * and greets that person. The message used to greet the person is a * <i>property</i> of the Greeter object. * * @author Wayne Pollock, Tampa Florida USA. * @see GreeterApp * @version 1.0 (1/2004) */ public class Greeter { /** The message to use in the greeting. */ private String message; /** A <i>constructor</i> that is used to initialize a Greeter * object's properties: the greeting message to use. * * @param message A <code>String</code> used to initialize * the Greater object with the greeting message to use. */ public Greeter ( String message ) { this.message = message; // Sets the message property // from the message argument } /** * A <i>method</i> used to greet the named person. * * @param name The name of the person to greet. */ public void greet ( String name ) { System.out.println( message + " " + name ); } } |
/** A class that demonstrates creating {@link Greeter} objects * and invoking methods on them. * |