Generating an API webpage from a Java source file with Javadoc-style comments

by Pete Sanderson for COMP 2100, August 2015

Assumes Windows 7. Assumes your source code already contains Javadoc-style comments.

Step 1: Launch a Command Prompt window

  1. Click the Start button, type cmd into the Search programs and files box, press Enter.
  2. A window should open with black background and white text.
  3. Its command prompt shows your current location in the file system.
  4. You can type DOS commands at this prompt. DOS commands are not case-sensitive.

Step 2: Browse to the folder containing your Java source code

  1. If the prompt is not Z:\>, type Z: then press Enter, to get it.
    Note: If your code is on a different drive, such as a flash drive, substitute its designated drive letter instead of Z.
  2. Browse to the directory (folder) containing your Java files. You will need its file path. You can get this in the lab by double-clicking the Home Folder desktop icon, then double-clicking through to the folder. The file path will be displayed along the top of the Windows Explorer window.
  3. At the Z:\> prompt, type cd (Change Directory) followed by a space, followed by the file path. Start with the first directory in the path and type in the whole path, substituting a backslash character (\) for each right arrow.
Background And Example
  1. You browse in DOS using the CD (Change Directory) command. A directory is the same thing as a folder.
  2. Example: The command cd documents is equivalent to double-clicking a folder icon called documents
  3. When you do this, the DOS prompt changes to display your new location in the file system.
  4. Once you've 'opened' a directory using CD, you can view its contents using the DIR command (DIRectory)
  5. You can browse to your destination one level at a time using a series of CD commands
  6. Alternatively, you can chain a sequence (path) of directories into one CD command using the '\' character as a separator.
  7. If you need to go in the reverse direction, to the "parent" directory, use CD with .. as your destination.

Example: current directory is Z:\ (your Z drive home folder) and you want to browse to your exercise1 folder. The path to get there from your home folder is through My Documents then COMP 2100

Z:\> cd My Documents\COMP 2100\exercise1

Step 3: Run javadoc

  1. Note: you must first CD to the directory containing your source code (see Step 2)
  2. The system will not know where the javadoc.exe executable file is located so you need to type in its complete directory path. This is shown below.
  3. At the DOS prompt, enter: c:\"Program Files"\Java\jdk1.7.0_05\bin\javadoc -d docs -public Classname.java
    NOTE: Substitute the name of your source file for Classname.java
    NOTE: The character following "jdk" is the digit 1, not lower case L.
  4. It will generate a bunch of HTML files. Messages will be displayed and the files will be placed in a folder called docs which will be located in the same folder as your source code. You don't have to call it docs, but that's an easy way to remember what's in it.

Step 4: View the results

  1. Open Windows Explorer and browse to the folder containing your source code. Then browse to the docs folder.
  2. Locate the Classname.html icon (substituting the name of your class for Classname). Double-click the file icon to display it in the default browser.

Step 5: Repeat until satisfied

Once you've displayed the results, you'll probably want to make some changes to your Javadoc comments. If so, just
  1. Edit and save your source file
  2. Repeat Step 4. You do not have to type in the command again! Just press the up-arrow key to go to the previous command. You can traverse the list of previous commands in both directions using the up-arrow and down-arrow keys. You can modify a command by using the left-arrow and right-arrow keys to reposition the cursor. Then edit changes using the backspace and delete keys to erase characters to be replaced.
  3. Repeat Step 5.