无法在目录中运行程序“npm”

当我遍历到src/main/app/文件夹结构,我有package.JSON &gruntfile,我能够运行npm installgrunt命令。 但是当我试图运行mvn jetty:run和项目的根文件夹中的一个属性文件当POM文件存在时,它将引发错误,它不能运行npm install在文件夹结构src/main/app/

这是确切的错误:

 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (n pminstall) on project my-abc-web: Command execution failed. Cannot run program "npm" (in directory "C:\Users\Achyut_J01\Documents\GitHub\infras\my-abc\my-abc-web\src\main\app"): CreatePro cess error=2, The system cannot find the file specified -> [Help 1] 

这是一个Windows机器。

显然你在Windows系统上。 npm是一个batch file,而不是一个可执行文件。 从maven exec插件运行batch file有问题 。 您可能想要探索链接中build议的解决方法,如

  • 将.bat脚本解构成其实际的命令
  • 使用cmd.exe并传递节点作为参数 – 参考这个 。

我使用这种解决方法来创build一个跨平台的Maven构build:将npm可执行文件的名称声明为Mavenvariables,并在Windows上运行时使用Mavenfilter来修改此可执行文件的名称。

它可以为Grunt,Bower等工作。

 <properties> <npm.executable>npm</npm.executable> </properties> (...) <build> <plugins> (...) <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.5.0</version> <executions> <execution> <id>exec-npm</id> <phase>process-resources</phase> <configuration> <executable>${npm.executable}</executable> <arguments> <argument>install</argument> </arguments> </configuration> <goals> <goal>exec</goal> </goals> </execution> </executions> </plugin> (...) </plugins> </build> <profiles> <profile> <id>platform-windows</id> <activation> <os> <family>windows</family> </os> </activation> <properties> <!-- Override the executable names for Windows --> <npm.executable>npm.cmd</npm.executable> <grunt.executable>grunt.cmd</grunt.executable> <bower.executable>bower.cmd</bower.executable> </properties> </profile> </profiles> 

在Windows平台中,使用npm.cmd来replacenpm