对于现有项目,如何使用ant生成javadoc?

时间:2009-09-30 03:31:18

标签: java ant build javadoc

我想从一个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>

Javadoc在哪里?它是隐藏文件还是放在该目录中的东西?

1 个答案:

答案 0 :(得分:15)

您定义的doc目标会在${doc.dir}中生成javadoc,并设置为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>

因此,要生成javadoc,只需运行:

$ ant doc

您可以在doc子目录中找到它。