java - ant exec 任务错误,代码=3

标签 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

我在谷歌上搜索过,该代码似乎是“权限被拒绝”,但我不知道如何解决这个问题。

最佳答案

一般来说,使用 Ant(和 Java),您不能直接执行 shell 脚本。您需要执行解释器/shell 并将脚本作为参数。

例如:

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

关于java - ant exec 任务错误,代码=3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29647280/

相关文章:

bash - 使用 printf 格式化输出 : truncating or padding

java - jQuery XSS 问题

java - MapByteBuffer 比 BufferReader 更快吗?

java - URLConnection 无法读取任何 header 字段,但 Firefox 可以

android - bash 列出所有目录,子目录,文件夹,子文件夹然后输出到一个单独的文件

linux - 使用 linux 脚本命令

tomcat - 取消部署目标无法正常工作

ant - 将输入传递给 Ant 的 <exec> 任务

java - Ant jar 任务仅包含单个类文件

java - 尝试从枚举类创建字符串的 ArrayList