引用说明:原文来自于 http://www.iteye.com/topic/874927 ,为了方便本人阅读,文本格式略有调整。
doxygen是用于从java源代码生成技术文档的工具,有些类似javadoc,但是比javadoc界面要漂亮许多,而且配合graphviz,可以生成带UML图表的文档。
doxygen可以通过ant插件集成到ant构建任务中,这样可以通过ant构建任务自动从最新的源代码中生成最新的文档。
看一下效果图吧:
Doxygen官网地址:http://www.stack.nl/~dimitri/doxygen/index.html
这么漂亮的文档时如何生成的呢?
一。安装
需要安装三个工具
1.graphviz linux安装参考http://hanqunfeng.iteye.com/blog/869293
2.doxygen linux安装参考http://hanqunfeng.iteye.com/blog/874154
3.doxygen的ant插件
前两个工具在windows下都有安装包,一步一步安装就行,linux安装参考所给连接即可。
这里只介绍第三个工具的安装,实际上就是一个ant的插件。
官网地址:http://sourceforge.net/projects/ant-doxygen/
目前最新版本为1.6.1
下载后解压即完成安装:
- tar -zxvf ant-doxygen-bin- 1.6 . 1 .tgz --directory=ant-doxygen
tar -zxvf ant-doxygen-bin-1.6.1.tgz --directory=ant-doxygen
其实我们要用到的就是ant-doxygen/lib/ant_doxygen.jar
二。编写ant任务
- <!-- ant-doxygen lib包路径 -->
- < property name = "ant_doxygen.lib" location = "${ant_doxygen.home}/lib" />
- <!-- doxygen路径 -->
- < property name = "ant_doxygen.dir" location = "${reports.dir}/doxygen" />
- < taskdef name = "doxygen" classname = "org.doxygen.tools.DoxygenTask" classpath = "${ant_doxygen.lib}/ant_doxygen.jar" />
- < target name = "doxygen" >
- < delete dir = "${ant_doxygen.dir}" />
- < mkdir dir = "${ant_doxygen.dir}" />
- < doxygen >
- < property name = "PROJECT_NAME" value = "${ant.project.name}" />
- < property name = "PROJECT_NUMBER" value = "0.1" />
- < property name = "OUTPUT_DIRECTORY" value = "${ant_doxygen.dir}" />
- < property name = "JAVADOC_AUTOBRIEF" value = "YES" />
- < property name = "TAB_SIZE" value = "4" />
- < property name = "OPTIMIZE_OUTPUT_JAVA" value = "YES" />
- < property name = "INPUT" value = "${src.dir}" />
- < property name = "RECURSIVE" value = "YES" />
- < property name = "HAVE_DOT" value = "YES" />
- < property name = "UML_LOOK" value = "YES" />
- < property name = "CLASS_GRAPH" value = "YES" />
- < property name = "COLLABORATION_GRAPH" value = "YES" />
- < property name = "GROUP_GRAPHS" value = "YES" />
- < property name = "DIRECTORY_GRAPH" value = "YES" />
- < property name = "SHOW_DIRECTORIES" value = "YES" />
- < property name = "SOURCE_BROWSER" value = "YES" />
- < property name = "STRIP_CODE_COMMENTS" value = "NO" />
- < property name = "GENERATE_LATEX" value = "NO" />
- < property name = "GENERATE_TREEVIEW" value = "YES" />
- </ doxygen >
- </ target >
<!-- ant-doxygen lib包路径 --> <property name="ant_doxygen.lib" location="${ant_doxygen.home}/lib" /> <!-- doxygen路径 --> <property name="ant_doxygen.dir" location="${reports.dir}/doxygen" /> <taskdef name="doxygen" classname="org.doxygen.tools.DoxygenTask" classpath="${ant_doxygen.lib}/ant_doxygen.jar"/> <target name="doxygen"> <delete dir="${ant_doxygen.dir}" /> <mkdir dir="${ant_doxygen.dir}" /> <doxygen> <property name="PROJECT_NAME" value="${ant.project.name}" /> <property name="PROJECT_NUMBER" value="0.1" /> <property name="OUTPUT_DIRECTORY" value="${ant_doxygen.dir}" /> <property name="JAVADOC_AUTOBRIEF" value="YES" /> <property name="TAB_SIZE" value="4" /> <property name="OPTIMIZE_OUTPUT_JAVA" value="YES" /> <property name="INPUT" value="${src.dir}" /> <property name="RECURSIVE" value="YES" /> <property name="HAVE_DOT" value="YES" /> <property name="UML_LOOK" value="YES" /> <property name="CLASS_GRAPH" value="YES" /> <property name="COLLABORATION_GRAPH" value="YES" /> <property name="GROUP_GRAPHS" value="YES" /> <property name="DIRECTORY_GRAPH" value="YES" /> <property name="SHOW_DIRECTORIES" value="YES" /> <property name="SOURCE_BROWSER" value="YES" /> <property name="STRIP_CODE_COMMENTS" value="NO" /> <property name="GENERATE_LATEX" value="NO" /> <property name="GENERATE_TREEVIEW" value="YES" /> </doxygen> </target>
以上配置基本上可以保证生成一个比较完整的文档,关于各个属性的介绍,可以参考如下地址:
http://hi.baidu.com/zkheartboy/blog/item/8ed283cae6a06c80c8176858.html
执行这个ant任务即可自动生成文档。
三。后记
doxygen生成的文档确实比javadoc生成的文档要漂亮许多,而且可以生成uml图表,不过javadoc配合UmlGraph,也可以生 成uml图表,而且通过UmlGraph还支持外部api的导航。不过doxygen比较强的的地方是其对注释格式的简单要求,以及可以在文档中显示源代 码,使文档更加完成。
关于UmlGraph的介绍可以参考http://hanqunfeng.iteye.com/blog/869576
两个工具各有优势,可依据具体情况进行选择。