sree
sree

Reputation: 535

ANT | Trying to override old definition of task javac Error

i am trying to build a jar in ANT.Below is my code for generating jar file.i dont know why this error("Trying to override old definition of task javac") happens.sometimes its not generating 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>

The output is as follows:

Buildfile: E:\GAD project\project\GAD\build.xml
Trying to override old definition of task javac
init:
    [mkdir] Created dir: E:\GAD project\project\GAD\dist
compile:
compress:
      [jar] Building jar: E:\GAD project\project\GAD\dist\sample.jar
BUILD SUCCESSFUL
Total time: 1 second

Let me know how can i rectify the error msg.?

Upvotes: 4

Views: 10205

Answers (3)

Wishmaster
Wishmaster

Reputation: 51

In general it happens when ant tasks are loaded multiple times from different sources.
For example:

    <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

Upvotes: 1

Varun Bhatia
Varun Bhatia

Reputation: 4396

I had the following import in my build.xml which was causing the issues

<import file="${sdk.dir}/tools/ant/build.xml" />

Upvotes: 0

Chamly Idunil
Chamly Idunil

Reputation: 1872

lets try this

<presetdef name="my.javac">
            <javac includeantruntime="false" />
    </presetdef>


    <target name="compile" depends="init">
        <my.javac srcdir="src" destdir="build/classes"/>
    </target>  

Upvotes: 4

Related Questions