不能用maven运行npm grunt bower

我有一个简单的networking应用程序,使用npm鲍尔和咕噜声。 我正在使用这个项目作为maven项目中的一个模块。 我search了互联网,发现如何定义项目的pom.xml,但我无法运行它。 任何人都可以告诉我如何使用maven构build和运行webapp的步骤。

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构build和运行这个pom?

你不能运行它的原因是因为它不是可执行文件,如果你不在windows上,它是一个batch file或shell脚本。

你仍然可以使用maven exec插件来运行它。 不过要做到这一点,你必须将batch filenpmcmd程序(或bash或任何你喜欢的shell)。

以下是你需要做的改变。

实际的命令将批次提交给cmd

 cmd /c "npm --version" 

以下是插件configuration的变化。

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

这应该工作。