我试图通过本教程学习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。
build.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));
}
}
- 如何解决这个问题
在ANT build.xml中,<docs>
目标正在尝试为"src"包生成文档。尝试使用正确的包名称,如<javadoc packagenames="src" sourcepath="...">
中的"math"(如packagenames="math,test"
)。您可以阅读ANT文档,其中包含javadoc
任务使用的示例。