我正在尝试为java jar运行ant构建文件。由于某种原因,每当我尝试运行ant run
时,它都会返回并说,"Element of type target must be terminated by the matching </target> tag
"。这似乎很奇怪,因为我看到我确实有一个终止标记来运行。会不会有别的原因导致这种情况?任何帮助将非常感激!
<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>
<target name= "run" depends = "jar">
<java fork='yes' jar="build/jar/KnightsTour.jar"/>
<arg value="${rows}"/>
<arg value="${columns}"/>
<arg value="${attempts}"/>
</java>
</target>
您正在关闭上面块中的Java标记两次,首先使用/>
内联,然后写入</java>
,这导致您的错误。这是修复后的样子:
<target name= "run" depends = "jar">
<java fork='yes' jar="build/jar/KnightsTour.jar" >
<arg value="${rows}"/>
<arg value="${columns}"/>
<arg value="${attempts}"/>
</java>
</target>
无论何时怀疑XML验证错误,都应该使用免费的在线XML验证实用程序来至少确认文件的结构是正确的。这是我用来快速定位错误的方法:http://www.xmlvalidation.com/index.php?id=1&L=0