amos
amos

Reputation: 5402

Why isn't Ant exec not using my path?

I have these lines in my build file:

    <property environment="env"/>
    ...
    <echo>Path: ${env.PATH}:/usr/local/bin</echo>
    <exec executable="cmake" searchpath="true" dir="${engine}">
        <env key="PATH" path="${env.PATH}:/usr/local/bin"/>
        <arg value=".." />
    </exec>

since my cmake installation is here:

> which cmake
cmake is /usr/local/bin/cmake

but when I build, I get this:

    [echo] Path: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

BUILD FAILED
build.xml:17: Execute failed: java.io.IOException: Cannot run program "cmake" (in directory "engine"): error=2, No such file or directory

whereas this works:

<exec executable="/usr/local/bin/cmake" searchpath="true" dir="${engine}">

If it matters, I'm on OSX, using Eclipse Mars 4.5.2. Assuming Eclipse is using ant on my path, it's:

> ant -version
Apache Ant(TM) version 1.9.6 compiled on June 29 2015

Upvotes: 3

Views: 1764

Answers (2)

M A
M A

Reputation: 72884

You actually didn't update the PATH env variable to contain /usr/local/bin. The buildfile is only appending it to an echo message. To update the variable, you can do:

<property environment="env"/>
<exec executable="cmake" searchpath="true" dir="${engine}">
   <env key="PATH" value="${env.PATH}:/usr/local/bin"/>
</exec>

Upvotes: 1

JP Moresmau
JP Moresmau

Reputation: 7403

Your PATH when looking for cmake does not contain /usr/local/bin. If cmake was found, then it would run with the PATH value you specified. The env element under exec is what's given the sub process, but it's not used by Ant itself. You need to modify the path before running ant or specify the full path as you do.

Upvotes: 2

Related Questions