ant exec任务错误代码= 3

时间:2015-04-15 10:02:42

标签: java bash ant

我试图从ant目标调用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

我在google上搜索过,那段代码似乎是“permision denied”,但我不知道如何才能解决这个问题。

1 个答案:

答案 0 :(得分:2)

通常使用Ant(和Java),您无法直接执行shell脚本。您需要执行解释器/ shell并将脚本作为参数。

例如:

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