我正在开发一些蚂蚁工具,下面是代码块:
<trycatch>
<try>
<if>
<equals arg1="${project.dir}" arg2=""/>
<then>
<fail/>
</then>
</if>
</try>
<catch>
<echo>

Project directory not found at the location: ${project.dir}

Please set your valid project directory in ant configuration file located under path: build/config.properties

-----------------------------|- Program Terminated -|-----------------------------
</echo>
</catch>
</trycatch>
和我也使用ant.contrib.jar for if, else…
等功能1问题是当ant抛出"project dir not found"这个错误时,ant程序得到终止该fine。但是在我的错误之后还显示了以下错误:
BUILD FAILED
D:Buildbuild.xml:151: The following error occurred while executing this line:
D:Buildbuild.xml:255: Execute failed: java.io.IOException: Cannot run program "java" (in directory "D:Buildpublish"): CreateProcess error=206, The filename or extension is too long
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:41)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:434)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:448)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:628)
at org.apache.tools.ant.taskdefs.ExecuteOn.runParallel(ExecuteOn.java:714)
at org.apache.tools.ant.taskdefs.ExecuteOn.runExec(ExecuteOn.java:477)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:495)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 38 more
那么我如何删除或控制这个BUILD FAIL错误?
我想你是想在<catch>
的情况下终止程序,所以你应该在最后添加一个<throw/>
。
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="test" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/usr/share/java/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="test">
<trycatch>
<try>
<if>
<equals arg1="true" arg2="true"/>
<then>
<echo>HIT</echo>
<fail/>
</then>
<else>
<echo>NO HIT</echo>
</else>
</if>
</try>
<catch>
<echo>

Project directory not found at the location: ${project.dir}

Please set your valid project directory in ant configuration file located under path: build/config.properties

-----------------------------|- Program Terminated -|-----------------------------
</echo>
<throw/>
</catch>
</trycatch>
<echo>AFTER ALL</echo> <!-- this shall not be called -->
</target>
</project>
产生如下结果:
test:
HIT
Project directory not found at the location: ${project.dir}
Please set your valid project directory in ant configuration file located under path: build/config.properties
-----------------------------|- Program Terminated -|-----------------------------
/home/mor/projekte/steamnet/DLH/test.xml:28: No message
BUILD FAILED (total time: 0 seconds)