I have the following Ant script:

<project name="build" default="all" basedir=".">
    <target name="all">
        <property name="srcDir" value="/root/CCM/src"/>
        <property name="srcProtobufJavaDir" 
value="/root/CCM/srcProtobufJava"/>
        <property name="prereqToolsDir" value="/root/protoc"/>
        <mkdir dir="${srcProtobufJavaDir}"/>
        <chmod file="${prereqToolsDir}/bin/protoc" perm="755"/>
        <exec executable="${prereqToolsDir}/bin/protoc">
            <!-- <arg value="${prereqToolsDir}/bin/protoc"/> -->
            <arg value="--java_out=${srcProtobufJavaDir}"/>
            <arg value="--proto_path=${srcDir}/protobuf/asf"/>
            <arg value="${srcDir}/protobuf/asf/*.proto"/>
            <env key="LD_LIBRARY_PATH" value="${prereqToolsDir}/lib"/>
       </exec>
    </target>
</project>

When I run this, I get:

[root@nc9042036240 ~]# /usr/apache-ant-1.9.4/bin/ant -v -f build.xml
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
Buildfile: /root/build.xml
Detected Java version: 1.7 in: 
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/jre
Detected OS: Linux
parsing buildfile /root/build.xml with URI = file:/root/build.xml
Project base dir set to: /root
Build sequence for target(s) `all' is [all]
Complete build sequence is [all, ]

all:
parsing buildfile 
jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml 
with URI = 
jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml 
from a zip file
    [mkdir] Skipping /root/CCM/srcProtobufJava because it already exists.
    [chmod] Executing 'chmod' with arguments:
    [chmod] '755'
    [chmod] '/root/protoc/bin/protoc'
    [chmod]
    [chmod] The ' characters around the executable and arguments are
    [chmod] not part of the command.
    [chmod] Applied chmod to 1 file and 0 directories.
     [exec] Current OS is Linux
     [exec] Setting environment variable: LD_LIBRARY_PATH=/root/protoc/lib
     [exec] Executing '/root/protoc/bin/protoc' with arguments:
     [exec] '--java_out=/root/CCM/srcProtobufJava'
     [exec] '--proto_path=/root/CCM/src/protobuf/asf'
     [exec] '/root/CCM/src/protobuf/asf/*.proto'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] /root/CCM/src/protobuf/asf/*.proto: No such file or directory
     [exec] Result: 1

Running the equivalent command manually works just fine:

/root/protoc/bin/protoc --java_out=/root/CCM/srcProtobufJava/ 
--proto_path=/root/CCM/src/protobuf/asf /root/CCM/src/protobuf/asf/*.proto

(It silently compiles a set of Google Protobuf files.)  I originally set 
the executable to "/bin/sh" and the protoc command was the first arg, 
which you can see commented out above.  With this arrangement, the exec 
task failed saying "cannot execute binary file" for protoc.  Where have I 
gone wrong here? 

Thanks!

Chris

Reply via email to