Ant程序终止

时间:2013-05-27 08:49:38

标签: java ant ant-contrib

我正在研究一些蚂蚁工具,以下是代码块:

<trycatch>
    <try>
        <if>
            <equals arg1="${project.dir}" arg2=""/>
            <then>
                <fail/>
            </then>
        </if>
    </try>
    <catch>
        <echo>
            &#xa;Project directory not found at the location: ${project.dir}
            &#xa;Please set your valid project directory in ant configuration file located under path: build/config.properties
            &#xa;-----------------------------|- Program Terminated -|-----------------------------
        </echo>
    </catch>
</trycatch>

我也在使用ant.contrib.jar for if,else ... etc functions

我的问题是当蚂蚁抛出“项目目录未找到”的错误时,蚂蚁程序终止就好了。但它在我的错误之后也显示我跟随错误:

BUILD FAILED
D:\Build\build.xml:151: The following error occurred while executing this line:
D:\Build\build.xml:255: Execute failed: java.io.IOException: Cannot run program "java" (in directory "D:\Build\publish"): 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错误?

1 个答案:

答案 0 :(得分:2)

我认为您希望在<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>
                    &#xa;Project directory not found at the location: ${project.dir}
                    &#xa;Please set your valid project directory in ant configuration file located under path: build/config.properties
                    &#xa;-----------------------------|- 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)