Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何处理从liquibase updateDatabase ant任务中获得的错误_Database_Ant_Error Handling_Return_Liquibase - Fatal编程技术网

如何处理从liquibase updateDatabase ant任务中获得的错误

如何处理从liquibase updateDatabase ant任务中获得的错误,database,ant,error-handling,return,liquibase,Database,Ant,Error Handling,Return,Liquibase,我目前正在开发一些ant,用于将liquibase更改应用于数据库。 我希望能够处理在ant中从liquibase updateDatabase任务中得到的错误。以下是我现在在构建文件中的内容(请记住,我现在的工作很好,我只需要能够处理运行liquibase时可能遇到的错误) 理想情况下,我希望能够将liquibase中的返回代码(而不是这段文本)输入到ant中,然后在此基础上执行以下操作: <echo message="this failed because ${reason}"/>

我目前正在开发一些ant,用于将liquibase更改应用于数据库。 我希望能够处理在ant中从liquibase updateDatabase任务中得到的错误。以下是我现在在构建文件中的内容(请记住,我现在的工作很好,我只需要能够处理运行liquibase时可能遇到的错误)

理想情况下,我希望能够将liquibase中的返回代码(而不是这段文本)输入到ant中,然后在此基础上执行以下操作:

<echo message="this failed because ${reason}"/>

但不限于此

我有没有办法从liquibase获得返回码?我的最佳猜测是,与ant exec任务类似,默认情况下,返回代码被忽略,我希望有某种方法可以实现它。欢迎任何建议


编辑:模糊相似的问题

ant contrib trycatch任务使我能够处理错误,这是一个合适的修复方法,因为堆栈跟踪实际上很有用


塔达!
捕获。
终于来了。
你需要下载ant contrib jar,如果你不想把它放在你的ant_家里,那么你可以使用它

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="PATH TO JAR"/>
  </classpath>
</taskdef>

似乎没有办法获得返回代码——任务没有实现它。
exec
可以获取返回代码的原因是它执行一个外部程序——这意味着一个新进程。对于常见的Ant任务,它只是一段代码,在当前Ant构建的相同过程中执行,因此无法获得任何“返回代码”。例如,如果任务通过套接字连接到数据库,或者直接打开数据库,则不会有新的进程,因此不会返回代码。是的,似乎是这样,我现在使用了ant contrib try catch任务,它至少可以让我处理故障。
<echo message="this failed because ${reason}"/>
<trycatch property="foo" reference="bar">
  <try>
    <fail>Tada!</fail>
  </try>

  <catch>
    <echo>In &lt;catch&gt;.</echo>
  </catch>

  <finally>
    <echo>In &lt;finally&gt;.</echo>
  </finally>
</trycatch>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="PATH TO JAR"/>
  </classpath>
</taskdef>