如何生成java api document 相似的文件幫助(1)

xchui702發表於2016-09-11
1.  綜述
java 的文件註釋功能: 在編寫java原始檔時候,使用
/**
@author: 指定Java程式的作者
@version: 指定原始檔的版本
@param: 方法引數的說明資訊
@return: 方法的返回值說明資訊
@exception: 丟擲異常的型別
@throws: 丟擲的異常, 與@exception同義
*/

定義註釋,就可以使用JDK提供的javadoc工具直接將原始碼裡的文件註釋提取成一份系統的API文件。

2. 程式碼舉例如下:

點選(此處)摺疊或開啟

  1. package com.std.crazy.dtnum;
  2. /**
  3.  *
  4.  * @author david
  5.  * <br/>website: <a href="http://www.***.org">crazy Java bind</>
  6.  * <br/>Copyright (C),2001-2012,
  7.  * <br/>This programs is protected by copyright david
  8.  * @version 1.0
  9.  */
  10. public class Student {

  11.     /**
  12.      * the name attribute
  13.      */
  14.     public String name;
  15.     /**
  16.      * the protected attribute of age
  17.      */
  18.     protected int age;
  19.     public String getName() {
  20.         return name;
  21.     }
  22.     /**
  23.      * set the name of student
  24.      * @param name the pointed name
  25.      */
  26.     public void setName(String name) {
  27.         this.name = name;
  28.     }
  29.     /**
  30.      * get the age of student
  31.      * @return the age of this student
  32.      */
  33.     public int getAge() {
  34.         return age;
  35.     }
  36.     public void setAge(int age) {
  37.         this.age = age;
  38.     }
  39. }

3. 執行javadoc命令如下

 切換到java 原始檔所在目錄  cd F:\kq\java_ecli_workspaces\workspaces\Bach\Crazy_Java\src\com\std\crazy\dtnum
    dir
    2016-09-11  09:43               757 Student.java
 
 javadoc -d F:\快錢\java_ecli_workspaces\apidoc -windowtitle 學生管理系統 javadoc 學生管理API文件 -header 我的類 -version -author

4. 執行結果
會生成一組html檔案, 


生成的API到此結束,下一篇將會掩飾對多個包生成API文件。

我們在開發中多使用/** */的註釋,可以自動生成api-doc檔案,那麼可以很好的程式程式的開發對接。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/674865/viewspace-2124795/,如需轉載,請註明出處,否則將追究法律責任。

相關文章