如何使用 ant 为现有项目生成 javadoc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1495982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate javadoc with ant, for an existing project?
提问by
I want to make a Javadoc from an ant build file, but I don't see where it is. In build.xml I have:
我想从 ant 构建文件制作 Javadoc,但我看不到它在哪里。在 build.xml 我有:
<description>
A sample build file for this project
</description>
<property name="source.dir" location="src"/>
<property name="build.dir" location="bin"/>
<property name="doc.dir" location="doc"/>
<property name="main.class" value="proj1.Proj1"/>
<target name="init" description="setup project directories">
<mkdir dir="${build.dir}"/>
<mkdir dir="${doc.dir}"/>
</target>
<target name="compile" depends="init" description="compile java sources">
<javac srcdir="${source.dir}" destdir="${build.dir}"/>
</target>
<target name="run" description="run the project">
<java dir="${build.dir}" classname="${main.class}" fork="yes">
<arg line="${args}"/>
</java>
</target>
<target name="clean" description="tidy up the workspace">
<delete dir="${build.dir}"/>
<delete dir="${doc.dir}"/>
<delete>
<fileset defaultexcludes="no" dir="${source.dir}" includes="**/*~"/>
</delete>
</target>
<!-- Generate javadocs for current project into ${doc.dir} -->
<target name="doc" depends="init" description="generate documentation">
<javadoc sourcepath="${source.dir}" destdir="${doc.dir}"/>
</target>
</project>
Where is the Javadoc located? Is it a hidden file or something placed in that directory?
Javadoc 在哪里?它是隐藏文件还是放置在该目录中的东西?
回答by Pascal Thivent
You have a doc
target defined that generates javadoc in ${doc.dir}
which is set to doc
.
您doc
定义了一个生成 javadoc的目标,${doc.dir}
其中设置为doc
.
<!-- Generate javadocs for current project into ${doc.dir} -->
<target name="doc" depends="init" description="generate documentation">
<javadoc sourcepath="${source.dir}" destdir="${doc.dir}"/>
</target>
So, to generate the javadoc just run:
因此,要生成 javadoc 只需运行:
$ ant doc
And you'll find it in the doc
sub directory.
你会在doc
子目录中找到它。
回答by easai
If you are using Eclipse, and your source files are under ${source.dir}/main, this works:
如果您使用的是 Eclipse,并且您的源文件位于 ${source.dir}/main 下,则此方法有效:
<target name="doc" depends="init" description="generate documentation">
<delete dir="${doc.dir}" />
<mkdir dir="${doc.dir}" />
<javadoc destdir="${doc.dir}">
<fileset dir="${source.dir}/main" />
</javadoc>
</target>