title: Execute npm with ant
body: <p>I want to automate the build of an application with frontend and backend. To do this I want to use maven with ant for platform independent copy and cli tasks. With some cli's like <code>docker ...</code> this works. But this does not work for cli's provided by <code>npm</code> or <code>npm</code> itself.</p>
  
  <pre><code>&lt;exec executable="docker"&gt;
      &lt;arg line="version"/&gt;
  &lt;/exec&gt;
  &lt;!--Works--&gt;
  &lt;exec executable="C:\Program Files\nodejs\npm.cmd"&gt;
      &lt;arg line="version"/&gt;
  &lt;/exec&gt;
  &lt;!--Doesn't work--&gt;
  &lt;exec executable="npm"&gt;
      &lt;arg line="version"/&gt;
  &lt;/exec&gt;
  </code></pre>
  
  <p>As seen in the second example, the script works if I specify the full path to the npm.cmd. But this should work at least on windows and unix. So specifying the full path is not an option. </p>
  
  <p>Is there any way to run <code>npm</code> and its modules from ant?</p>
  
  <hr>
  
  <p><strong>Late edit:</strong></p>
  
  <p>The real problem was, that the windows node installer also placed a file named <code>npm</code> into the bin folder which is a bash script meant for cygwin. The npm bin folder was added to the 'global' <code>PATH</code> env var and the windows cmd did pick up the correct binary because it uses the <code>PATHEXT</code> env var to determine what is executable and what not. The ant exec plugin does not use <code>PATHEXT</code> and just executes the first file named <code>npm</code> which fails. The <strong>Solution</strong> was to rename the plain <code>npm</code> file in the path. This way ant sees the <code>npm.cmd</code> file first and everything runs smoothly.</p>