BlueGirl
BlueGirl

Reputation: 501

Error with target in building by build.xml

I have opened a project which has build.xml and ivy.xml in eclipse env. after I applied Run As..>Ant Built by right click build.xml, I faced this error:

    BUILD FAILED
Target "retrieve" does not exist in the project "aaa". It is used from target "compile".

my build.xml file:

<project name="WOE" default="build">

    <!--<import file="../build/ivy-targets.xml"/>-->

    <property name="dir.base" location="."/>
    <!--<property name="dir.repos" location="${dir.base}/../repository/modules"/>-->
    <property name="dir.src" location="${dir.base}/src/java"/>
    <property name="dir.lib" location="${dir.base}/src/lib"/>
    <property name="dir.ivy.lib" location="${dir.base}/lib"/>
    <property name="dir.build" location="${dir.base}/build"/>
    <property name="dir.classes" location="${dir.build}/classes"/>
    <property name="module.jar" location="${dir.build}/WOEParse.jar"/>

    <property name="dir.doc" location="${dir.base}/doc"/>
    <property name="dir.javadoc" location="${dir.doc}/api"/>

    <path id="classpath">
        <fileset dir="${dir.lib}" includes="*.jar"/>
        <fileset dir="${dir.ivy.lib}/default" includes="*.jar"/>
        <!--<pathelement path="${dir.repos}/edu.stanford/BaselineNLProcessor/521/jars/baseline-nlprocessor-2010-06-22-521.jar" />-->
    </path>

    <path id="run.classpath">
        <path refid="classpath"/>
        <pathelement location="${module.jar}"/>
    </path>

    <target name="clean" description="Deletes artifacts produced by build">
        <delete dir="${dir.build}"/>
        <delete dir="${dir.javadoc}"/>
        <delete dir="${dir.ivy.lib}"/>
    </target>

     <target name="compile" depends="retrieve" description="Compiles source code">
        <mkdir dir="${dir.classes}"/>
        <javac destdir="${dir.classes}"
               debug="true"
               target="1.6">
            <classpath refid="classpath"/>
            <src path="${dir.src}"/>
        </javac>

    </target>

    <target name="build" depends="compile" description="Builds module JAR file">
        <jar jarfile="${module.jar}">
            <fileset dir="${dir.classes}" includes="**/*.class"/>
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="build" description="Processes a simple example file">
        <java classname="edu.washington.cs.woe.WOEParse" fork="true" failonerror="true">
            <jvmarg value="-Xmx1G"/>
            <classpath refid="run.classpath"/>
            <arg line="-inFile ./light-config/data/testSentenceFile -cfDir ./light-config/"/>
        </java>
    </target>

    <target name="javadoc" description="Builds javadoc html files for this source code">
        <mkdir dir="${dir.javadoc}"/>
        <javadoc classpathref="classpath" destdir="${dir.javadoc}" sourcepath="${dir.src}">
            <packageset dir="${dir.src}" defaultexcludes="yes">
            </packageset>
        </javadoc>
    </target>


</project>

The error is occurred in this part:

enter image description here

I changed it to

<target name="compile"  description="Compiles source code">

but it shows another error:

Buildfile: D:\eclipse workspace\WOE\build.xml
compile:
    [mkdir] Created dir: D:\eclipse workspace\WOE\build\classes
    [javac] D:\eclipse workspace\WOE\build.xml:38: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 42 source files to D:\eclipse workspace\WOE\build\classes

BUILD FAILED
D:\eclipse workspace\WOE\build.xml:38: D:\eclipse workspace\WOE\lib\default does not exist.

Total time: 328 milliseconds

What should I do? Is there any problem with eclipse env?(I dont have any ant plugin or etc. in Eclipse env), if so, which plugin should I use in eclipse to maybe properly open such projects?

Please help me. Thanks

Upvotes: 0

Views: 9508

Answers (3)

Haining Geng
Haining Geng

Reputation: 1

Go to Preference, check "Ignore all buildfile problems".

https://i.sstatic.net/8SiqM.png

Upvotes: 0

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77961

Is this a build file created by copy-n-pasting from another build file?

First issue

You have a compile target that depends on another non-existent target called "retrieve"

 <target name="compile" depends="retrieve" description="Compiles source code">
    <mkdir dir="${dir.classes}"/>
    <javac destdir="${dir.classes}"
           debug="true"
           target="1.6">
        <classpath refid="classpath"/>
        <src path="${dir.src}"/>
    </javac>
</target>

When using ivy it's quite common to have a target that first resolves (downloading if necessary) 3rd party jar dependencies. This is necessary in order to compile your code.

Second issue

Your second error is thrown by the following part of your build:

<path id="classpath">
    <fileset dir="${dir.lib}" includes="*.jar"/>
    <fileset dir="${dir.ivy.lib}/default" includes="*.jar"/>
    <!--<pathelement path="${dir.repos}/edu.stanford/BaselineNLProcessor/521/jars/baseline-nlprocessor-2010-06-22-521.jar" />-->
</path>

The code is expecting to find jars in the ${dir.ivy.lib}/default directory. Presumably this happens as part of the missing retrieve task.

Working example using ivy

Hope this helps.

Upvotes: 1

Dmitry Zinkevich
Dmitry Zinkevich

Reputation: 3623

The error is here:

 <target name="compile" depends="retrieve"

Either declare target with the name 'retrieve' or remove the dependency.

Upvotes: 1

Related Questions