2015年11月2日 星期一

自動產生Java API 文件檔

這超好用
就算不是在寫公用API
也可以寫給自己用
可以自動產生網頁版的API文件
這裡示範一個簡單的用法:

1. 使用 /** --*/ 為程式碼下注解
示範用類別:
package learning.test;

import java.util.ArrayList;

public class InventorySystem {
 /** 道具欄的總格數 */
 int totalGrid;
 /** 物品儲存List */
 ArrayList&ltObject&gt al;

 /** 建構函式 */
 public InventorySystem(int totalGrid) {
  super();
  this.totalGrid = totalGrid;
  al = new ArrayList&ltObject&gt(totalGrid);
 }

 /** 將物品放入道具欄 */
 public static boolean putItem(Object item) {
  return true;
 }

 /** 藉由物品id取得物品 */
 public static Object getItemObjectById(int id) {
  return new Object();
 }

 /** 藉由物品id取得物品數量 */
 public static int getItemNumberById(int id) {
  return 520;
 }
}

2.Eclipse 上選Project -> Generate Javadoc




3.在Javadoc command 欄位上填入javadoc的位址,選好要輸出的java檔

4.連續按兩次Next, 在VM opstions 上填入     
-encoding UTF-8 -charset UTF-8      
(避免編碼錯誤)

5.Doc文件出現啦!!~


沒有留言:

張貼留言