2016-08-16 208 views
1

我有一個簡單的使用npm bower和grunt的web應用程序。我正在使用這個項目作爲maven項目中的一個模塊。我搜索了互聯網,發現如何爲項目定義pom.xml,但我無法運行它。任何人都可以告訴我如何使用maven構建和運行webapp的步驟。無法使用maven運行npm grunt bower

,我得到的pom.xml

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.5.0</version> 
       <executions> 
        <execution> 
         <id>exec-npm-install</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <executable>npm</executable> 
          <arguments> 
           <argument>install</argument> 
          </arguments> 
         </configuration> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>exec-bower-install</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <executable>bower</executable> 
          <arguments> 
           <argument>install</argument> 
          </arguments> 
         </configuration> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>exec-grunt</id> 
         <phase>process-resources</phase> 
         <configuration> 
          <executable>grunt</executable> 
         </configuration> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

的錯誤是

[ERROR] Command execution failed. 
java.io.IOException: Cannot run program "C:\Program Files\nodejs\npm" (in directory "C:\Users\krs\IdeaProjects\project"): CreateProcess error=193, %1 is not a valid Win32 
application 

如何建立和使用maven運行此POM?

回答

4

您無法運行它的原因是因爲它不是可執行文件,如果您不在Windows上,它是批處理文件或shell腳本。

你仍然可以使用maven exec插件來運行它。然而要做到這一點,你必須提供批處理文件npmcmd程序(或bash或任何你最喜歡的shell)。

以下是您需要進行的更改。

實際命令喂批次到CMD

cmd /c "npm --version" 

以下是在插件配置中的變化。

<configuration> 
    <executable>cmd</executable> <!-- or bash --> 
    <workingDirectory>./</workingDirectory> 
    <arguments> 
    <argument>/c</argument> 
    <argument>"npm --version"</argument> 
    </arguments> 
</configuration> 

這應該有效。