4

我试图通过本教程Apache Ant - 教程来学习 apache ant

但是在我逐步创建构建文件并运行它之后,它会抛出:

compile:
    [javac] /home/nazar_art/workspace/de.vogella.build.ant.first/src/test/build.xml:27: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
jar:
      [jar] Building MANIFEST-only jar: /home/nazar_art/workspace/de.vogella.build.ant.first/src/test/dist/de.vogella.build.test.ant.jar
docs:

BUILD FAILED
/home/nazar_art/workspace/de.vogella.build.ant.first/src/test/build.xml:34: No source files and no packages have been specified.

我不明白为什么会这样?我使用 Ubuntu 12.04 操作系统和 Eclipse Indigo。

构建.xml:

<?xml version="1.0"?>
<project name="Ant-Test" default="main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="src.dir" location="src" />
  <property name="build.dir" location="bin" />
  <property name="dist.dir" location="dist" />
  <property name="docs.dir" location="docs" />

  <!-- Deletes the existing build, docs and dist directory-->
  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="${docs.dir}" />
    <delete dir="${dist.dir}" />
  </target>

  <!-- Creates the  build, docs and dist directory-->
  <target name="makedir">
    <mkdir dir="${build.dir}" />
    <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">
    <javac srcdir="${src.dir}" destdir="${build.dir}">
    </javac>

  </target>

  <!-- Creates Javadoc -->
  <target name="docs" depends="compile">
    <javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
      <!-- Define which files / directory should get included, we include all -->
       <fileset dir="${src.dir}">
                <include name="**" />
           </fileset>
    </javadoc>
  </target>

  <!--Creates the deployable jar file  -->
  <target name="jar" depends="compile">
    <jar destfile="${dist.dir}\de.vogella.build.test.ant.jar" basedir="${build.dir}">
      <manifest>
        <attribute name="Main-Class" value="test.Main" />
      </manifest>
    </jar>
  </target>

  <target name="main" depends="compile, jar, docs">
    <description>Main target</description>
  </target>

</project> 

代码部分:

package math;

public class MyMath {
  public int multi(int number1, int number2) {
    return number1 * number2;
  }
} 

package test;

import math.MyMath;

public class Main {
  public static void main(String[] args) {
    MyMath math = new MyMath();
    System.out.println("Result is: " + math.multi(5, 10));
  }
} 
  • 如何解决这个麻烦?
4

1 回答 1

0

在您的 ANT build.xml 中,<docs>目标正在尝试为“src”包生成文档。<javadoc packagenames="src" sourcepath="...">尝试在like中使用正确的包名称,例如“math” packagenames="math,test"。您可以阅读ANT 文档,其中包含javadoc任务使用示例。

于 2013-08-08T10:48:15.830 回答