2017-04-05 223 views
1

當我試圖運行下面的Ant腳本,它執行「故宮」命令:運行NPM,NG使用Windows Ant腳本命令,「系統找不到指定的文件」的錯誤

<target name ="test"> 
    <exec executable="npm" failonerror="true"> 
     <arg value="install" /> 
    </exec> 
</target> 

它失敗,此錯誤:

:當我嘗試運行角CLI 「NG」命令

Execute failed: java.io.IOException: Cannot run program "npm" 
(in directory "C:\Development\workspace\traqpath\WebSource"): 
CreateProcess error=2, The system cannot find the file specified 

同樣的情況,

<target name ="test"> 
     <exec executable="ng" failonerror="true"> 
      <arg value="build"/> 
      <arg value="--prod"/> 
      <arg value="--bh"/> 
     </exec> 
</target> 

在相同的錯誤消息,但對於「NG」:

Execute failed: java.io.IOException: Cannot run program "ng" 
(in directory "C:\Development\workspace\traqpath\WebSource"): 
CreateProcess error=2, The system cannot find the file specified 

兩個命令運行而無需在Windows命令行,這意味着的NodeJS安裝正確的問題,的NodeJS路徑在正確配置PATH系統變量。

我的新Ant腳本看起來像現在這樣:

回答

1

我通過修改Ant腳本指定「故宮」可執行文件的全名,(而在第二種情況下,「NG」命令),解決了這個問題:

<target name ="test"> 
    <exec executable="npm.cmd" failonerror="true"> 
     <arg value="install" /> 
    </exec> 
</target> 

<target name ="test"> 
     <exec executable="ng.cmd" failonerror="true"> 
      <arg value="build"/> 
      <arg value="--prod"/> 
      <arg value="--bh"/> 
     </exec> 
</target> 

請注意,我用「npm.cmd」,而不是 「故宮」,並「ng.cmd」,而不是 「NG」。

+1

直到明天,我被允許:) – Ghayth

-2
<target name ="test"> 
     <exec executable="ng" failonerror="true"> 
      <arg value="build"/> 
      <arg value="--prod"/> 
      <arg value="--bh"/> 
     </exec> 
</target> 

當我試圖在Linux上運行,它再次給予同樣的錯誤,他說 執行失敗:產生java.io.IOException:不能運行程序「NG」 ....

如何運行在linux env通過ANT

+1

這不是問題的答案。 – jdv

0

我解決了它類似於你的解決方案,除了我調用了「npm build」,這是默認包含在package.json下的「scripts」部分。

<target name="build_windows"> 
    <exec executable="npm.cmd" failonerror="true"> 
    <arg value="run-script"/> 
    <arg value="build"/> 
    </exec> 
</target> 

我甚至推出了類似的「建」另一個NPM腳本行命名爲「buildprod」是這樣的:

"scripts": { 
    "build": "ng build -bh /context/", 
    "buildprod": "ng build --prod --aot -bh /context/" 
} 

然後在我的Ant build.xml文件推出了類似的目標爲生產構建是這樣的:

<target name="build_prod_windows"> 
    <exec executable="npm.cmd" failonerror="true"> 
    <arg value="run-script"/> 
    <arg value="buildprod"/> 
    </exec> 
</target> 

這樣一來,就可以保持相同的ant腳本在其他角項目,不必擔心你的build.xml文件保存不同的參數。相反,你需要確保你的package.json具有正確的腳本。

相關問題