Ant构建中的Javadoc任务失败

时间:2019-05-29 00:49:06

标签: java ant javadoc

当我尝试运行Javadoc ant任务时,我收到了来自Ant的错误消息。

“建立失败 /data/data/com.termux/files/home/LearnJava/Observer/build.xml:39:未指定任何源文件,任何包和模块。”

构建文件位于:

https://github.com/Fernal73/LearnJava/blob/master/Observer/build.properties

version=1.0.0
main.class=com.javacodegeeks.patterns.observerpattern.TestObserver
main.class1=com.javacodegeeks.patterns.observerpattern.Test
cs.properties=../checkstyle.properties
gformat.properties=../gformat.properties
ant.build.javac.source=1.7
ant.build.javac.target=1.7
packages=com.javacodegeeks.patterns.observerpatern.*

https://github.com/Fernal73/LearnJava/blob/master/Observer/build.xml

<?xml version="1.0"?>
<project name="Observer" default="main"
  basedir=".">
  <property file = "build.properties"/>
  <property file = "${cs.properties}"/>
  <property file = "${gformat.properties}"/>
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="src.dir" location="." />
    <property name="build.dir" location="." />
    <property name="dist.dir" location="dist" />
    <property name="docs.dir" location="docs" />
    <taskdef resource="${cs.taskdef.resource}"
      classpath="../${cs.jar}"/>
    <!-- Deletes the existing build, docs and dist directory-->
    <target name="clean">
        <delete>
            <fileset dir="." includes="**/*.class"/>
    </delete>       
        <delete dir="${docs.dir}" />
        <delete dir="${dist.dir}" />
    </target>
    <!-- Creates the  build, docs and dist directory-->
    <target name="makedir">
        <mkdir dir="${docs.dir}" />
        <mkdir dir="${dist.dir}" />
    </target>
    <!-- Compiles the java code (including the usage of library for JUnit -->
    <target name="compile" depends="clean, makedir,gformat,checkstyle">
        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<compilerarg value="-Xlint:-options"/>
        </javac>
    </target>
    <!-- Creates Javadoc -->
    <target name="docs" depends="compile">
      <javadoc  packagenames="${packages}" additionalparam="-Xdoclint:none" 
        sourcepath="${src.dir}" 
        destdir="${docs.dir}">
            <!-- Define which files / directory should get included, we include all -->
             <fileset dir="${src.dir}">
                <include name="*.java" />
             </fileset>
        </javadoc>
      </target>
      <target name="manifest">
        <tstamp/>
      <manifest file="manifest.mf">
  <attribute name="Built-By" value="${user.name}"/>
<section name="common">
    <attribute name="Specification-Title" value="${ant.project.name}"/>
    <attribute name="Specification-Version" value="${version}"/>
    <attribute name="Specification-Vendor" value=""/>
    <attribute name="Implementation-Title" value=""/>
    <attribute name="Implementation-Version" value="${build} ${TODAY}"/>
    <attribute name="Implementation-Vendor" value=""/>
  </section>
  <attribute name="Main-Class" value="${main.class}" />
</manifest>
</target>
    <!--Creates the deployable jar file  -->
    <target name="jar" depends="compile,manifest">
      <jar destfile="${dist.dir}\${ant.project.name}.jar" basedir="${build.dir}" includes="**/*.class"
        manifest="manifest.mf">
</jar>
</target>
<target name="run" >
<description>Run target</description>
<java classname="${main.class}">
 <classpath>
   <pathelement location="${dist.dir}\${ant.project.name}.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="gformat">
  <exec executable="find" dir="${basedir}"
    failonerror="true" outputproperty="sources"> 
            <arg line=" . -type f -name '*.java'"/>  
          </exec>
          <echo message="About to format ...: ${sources}"/>
          <java classname="${gformat.main.class}">
            <arg line=" -i ${sources}"/>
 <classpath>
   <pathelement location="../${gformat.jar}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
    </target>
<target name="checkstyle">
  <first id="checkstylefile">
    <fileset dir=".." includes="${cs.config}"/>
  </first>
  <checkstyle config="${toString:checkstylefile}"
    classpath="../${cs.jar}"
    failOnViolation="false" properties="${cs.properties}">
  <fileset dir="${src.dir}" includes="**/*.java"/>
  <formatter type="plain"/>
  <formatter type="plain" toFile="${cs.output}"/>
</checkstyle>
</target>
<target name="main" depends="compile, jar, docs">
        <description>Main target</description>
    </target>
</project>

分别。

我在存储库上的其他项目具有类似的配置。

它们按预期工作。

我缺少明显的东西吗?

我确实错过了一些显而易见的事情。属性包中有一个额外的“ t”。显然,几个小时后,我将需要两眼或另一双眼睛!

1 个答案:

答案 0 :(得分:2)

我认为问题出在以下部分:

<fileset dir="${src.dir}">
    <include name="*.java" />
</fileset>

在Ant中,“ *.java”表示名称与* .java匹配的所有文件。这不会在子目录中搜索。 要包括所有子目录,您必须指定:

<fileset dir="${src.dir}">
    <include name="**/*.java" />
</fileset>

但是由于您已经指定了sourcePath属性,所以我想知道是否不能仅删除fileset元素,因为ant默认会添加** / *。java。