簡體   English   中英

ant exec 任務錯誤,代碼為 3

[英]ant exec task error with code=3

我試圖從螞蟻目標調用 bash 腳本。 這是我的目標:

<target name="report" depends="test">
    <!-- Step 3: Create coverage report -->
    <exec executable="./checkStyle.sh"
            failonerror="true"
            osfamily="unix"/>
    <jacoco:report>

        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${result.exec.file}" />
        </executiondata>

        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Ant Example">
            <classfiles>
                <fileset dir="${result.classes.dir}" />
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="${src.dir}" />
            </sourcefiles>
        </structure>

        <!-- to produce reports in different formats. -->
        <html destdir="${result.report.dir}" />
        <csv destfile="${result.report.dir}/report.csv" />
        <xml destfile="${result.report.dir}/report.xml" />
    </jacoco:report>
</target>

我的 bash 腳本是:

#!/bin/bash
DEST_FOLDER='./target/checkstyle'
CLASSES_FILE='classes.txt'
REPORT_FILE='report.xml'
mkdir -p "$DEST_FOLDER"

rm -f "$DEST_FOLDER/$CLASSES_FILE"
rm -f "$DEST_FOLDER/$REPORT_FILE"

find ./project -name "*.java" >> "$DEST_FOLDER/$CLASSES_FILE"
while read p; do 
    java -jar ./utilJars/checkstyle-6.5-all.jar -c ./sun_checks.xml -f xml $p >> "$DEST_FOLDER/$REPORT_FILE"
done < $DEST_FOLDER/$CLASSES_FILE

輸入 ./checkStyle 時一切正常,但是當我嘗試“ant report”時,會出現以下錯誤:

BUILD FAILED
/home/luci/workspace/operations/build.xml:60: exec returned: 3

Total time: 4 seconds

我在谷歌上搜索過,該代碼似乎是“權限被拒絕”,但我不知道如何解決這個問題。

通常使用 Ant(和 Java),您不能直接執行 shell 腳本。 您需要執行解釋器/shell 並將腳本作為參數提供。

例如:

    <exec executable="/bin/bash" failonerror="true" osfamily="unix">
        <arg value="-c"/>
        <arg value="./checkStyle.sh"/>
    </exec>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM