我正在尝试在ANT中构建一个jar。下面是我生成jar文件的代码。我不知道为什么会发生这个错误("试图覆盖任务javac的旧定义")。有时它不会生成jar。
<?xml version="1.0" ?>
<project name="HelloWorld" default="compress">
<presetdef name="javac">
<javac includeantruntime="false" />
</presetdef>
<target name="init">
<mkdir dir="build/classes" />
<mkdir dir="dist" />
</target>
<target name="compile" depends="init">
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="compress" depends="compile">
<jar destfile="dist/sample.jar" basedir="build/classes" />
</target>
<target name="execute" depends="compile">
<java classname="src" classpath="build/classes" />
</target>
<target name="clean">
</target>
</project>
输出如下:
Buildfile: E:GAD projectprojectGADbuild.xml
Trying to override old definition of task javac
init:
[mkdir] Created dir: E:GAD projectprojectGADdist
compile:
compress:
[jar] Building jar: E:GAD projectprojectGADdistsample.jar
BUILD SUCCESSFUL
Total time: 1 second
让我知道如何纠正错误消息。?
让我们试试这个
<presetdef name="my.javac">
<javac includeantruntime="false" />
</presetdef>
<target name="compile" depends="init">
<my.javac srcdir="src" destdir="build/classes"/>
</target>
通常,当从不同的源多次加载ant任务时,就会发生这种情况
例如:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${location1}/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${location2}/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="ping">
<echo message="pong"/>
</target>
Output:
..
Trying to override old definition of task addCredentials
Trying to override old definition of task clearCredentials
Trying to override old definition of task purgeExpiredCookies
Trying to override old definition of task postMethod
Trying to override old definition of task getMethod
Trying to override old definition of task headMethod
Trying to override old definition of task importurl
ping:
[echo] pong
BUILD SUCCESSFUL
我的build.xml中有以下导入,这导致了问题
<import file="${sdk.dir}/tools/ant/build.xml" />