Search code examples
javaxmlanttermination

ant build file terminating tag error


I am trying to run an ant build file for a java jar. For some reason, whenever I try to run ant run, it comes back and says, "Element of type target must be terminated by the matching </target> tag" This seems strange because I see that I do have a terminating tag for run. Would there be something else that could be causing this? Any help would be greatly appreciated!

<project>
        <target name="compile">
            <mkdir dir="build/classes"/>
            <javac includeantruntime="false" srcdir="." destdir="build/classes"/>
        </target>

        <target name="jar">
            <mkdir dir="build/jar"/>
            <jar destfile="build/jar/KnightsTour.jar" basedir="build/classes">
            <manifest>
                    <attribute name="Main-Class" value="PlayTour"/>
                </manifest>
                    </jar>
        </target>

        <target name= "run" depends = "jar">
            <java fork='yes' jar="build/jar/KnightsTour.jar"/>
                    <arg value="${rows}"/>
                    <arg value="${columns}"/>
                    <arg value="${attempts}"/>
            </java>
        </target>

        <target name="view">
                    <exec executable="less">
                            <arg value="PlayTour.java" />
                            <arg value="KnightsTour.java" />
                    </exec>
        </target>

            <target name= "doc">
                    <mkdir dir="build/docs"/>
                    <javadoc sourcefiles="KnightsTour.java, PlayTour.java" destdir="build/docs"/>
            </target>


    </project>

Solution

  •     <target name= "run" depends = "jar">
            <java fork='yes' jar="build/jar/KnightsTour.jar"/>
                    <arg value="${rows}"/>
                    <arg value="${columns}"/>
                    <arg value="${attempts}"/>
            </java>
        </target>
    

    You are closing the Java tag in the block above twice, first using /> in-line then writing </java>, which causes your error. This is what it looks like fixed:

        <target name= "run" depends = "jar">
            <java fork='yes' jar="build/jar/KnightsTour.jar" >
                    <arg value="${rows}"/>
                    <arg value="${columns}"/>
                    <arg value="${attempts}"/>
            </java>
        </target>
    

    Whenever you suspect an XML validation error, you should use a free online XML validation utility to at least confirm that the structure of your file is correct. This is what I used to quickly locate your error: http://www.xmlvalidation.com/index.php?id=1&L=0