我正在编写一个Java应用程序,它允许我只基于Java的文件结构来编译一个Java项目,这样我就可以在不使用IDE的情况下编写代码和编译。我目前遇到的问题是,我希望在编译时自动生成javadoc,尽管Java 6提供了一个可以使用的JavaCompiler对象,但我无法找到使用javadoc命令的方法。
如何使用Java代码为我的项目生成javadoc?
发布于 2011-08-10 00:15:02
如果您不知道Apache Ant和阿帕奇·马文都是工具,可以实现与您正在编写的类似的目标(在没有IDE的情况下编译)。
它们都支持生成javadoc。Ant语法如下所示:
<!-- publish javadoc -->
<target name="javadoc" description="Creates javadoc for IMP.">
<delete dir="${web-javadoc}"/>
<javadoc sourcepath="${source}"
defaultexcludes="no"
destdir="${web-javadoc}"
author="true"
version="true"
use="true"
windowtitle="IMP: Integrated Mechanisms Program"
overview="${source}/overview.html"
classpathref="debug.classpath"
stylesheetfile="${javadoc-theme}/stylesheet.css"
/>
<copy file="${javadoc-theme}/javadoc.jpg" tofile="${web-javadoc}/javadoc.jpg"/>
</target>如果您真的想自己生成它,则需要使用Doclet
import com.sun.javadoc.*;
public class ListClass {
public static boolean start(RootDoc root) {
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; ++i) {
System.out.println(classes[i]);
}
return true;
}
}发布于 2011-08-10 00:06:53
Javadoc工具有一个编程接口,它具有公共方法,用于从用Java语言编写的另一个程序调用Javadoc工具。这些方法位于
com.sun.tools.javadoc.Main类中的lib/tools.jar中。
来自:http://download.oracle.com/javase/6/docs/technotes/guides/javadoc/standard-doclet.html#runningprogrammatically
发布于 2011-08-10 00:07:28
在终端中,输入javadoc -它会给出一个很好的选项列表。最简单的:
javadoc -d your_output_directory -classpath your_classpath -sourcepath your_sourcefile_dirhttps://stackoverflow.com/questions/7004464
复制相似问题