[英]How do I do a custom exit status in my Java program written in jRuby?
我正在研究驗證工具的通用基礎,我希望將其作為JAR分發並使用Ant自動化。 單獨使用Java,我可以做類似的事情
...
int validationResults = this.validate();
System.exit(validationResults) // via Ant: 1 = "BUILD FAILED", 0 = "BUILD SUCCESSFUL"
...
使用CI系統在預定構建中使用驗證工具。
然而,我在jRuby而不是Java(用於學習)中寫這個。 我嘗試了以下方法,但它們不會在Ant中觸發“BUILD FAILED”。
java.lang.System.exit(1) # using "require 'java'" at the the top of the file
Kernel.exit 1
exit 1
我已經在jRuby問題跟蹤器中看到了關於此的門票(例如JRUBY-1650 ),但我還沒有找到解決問題的方法。
我正在運行jRuby v1.6.6和Warbler v1.3.2。 Ant目標如下所示:
<target name="validate">
<java jar="./validator.jar" fork="true" />
</target>
是我做得不對,還是jRuby不支持這個(還)?
我想你從java
Ant任務開始你的jRuby代碼。
要在jRuby進程中出現非零退出代碼時使Ant失敗,必須將java任務的failonerror
屬性設置為true
。
這是我用來觸發構建失敗的kludge,否則ant無法識別退出代碼。 它需要ant-contrib
。
在螞蟻:
<delete file="${java.io.tmpdir}/build-executable-error"/>
<exec executable= ... />
<if>
<resourceexists>
<file file="${java.io.tmpdir}/build-executable-error"/>
</resourceexists>
<then>
<loadfile srcfile="${java.io.tmpdir}/build-executable-error"
property="build.failure.message"/>
<fail message="${build.failure.message}"/>
</then>
</if>
然后,可執行文件負責在任何錯誤情況下創建和填充文件${java.io.tmpdir}/build-executable-error
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.