Maven无法执行目标-无法运行程序npm [英] Maven failed to execute goal - cannot run program npm

查看:1244
本文介绍了Maven无法执行目标-无法运行程序npm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7计算机上,并且得到必须运行"mvn install"才能构建应用程序的代码.当我这样做时,出现以下错误:

I am on a Windows 7 computer and I've been given code that I have to run "mvn install" on to build the app. When I do this, I get the following error:

无法在项目[project]上执行目标org.codehaus.mojo:exec-maven-plugin:1.2.1:exec(npm-install):命令执行失败.:无法运行程序"npm"(在目录"C:\ Users \ path \ to \ a \ folder):CreateProcess错误= 2,系统找不到指定的文件

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project [project]: Command execution failed.: Cannot run program "npm" (in directory "C:\Users\path\to\a\folder"): CreateProcess error=2, The system cannot find the file specified

该应用程序本身分为几个部分,其中之一是使用npm的角度应用程序.

The app itself is split into several parts, one of which is an angular app that npm is being used for.

我尝试安装nodejs(我不太熟悉)并将其包含在PATH中,但是无论如何都会发生相同的错误. maven是否应该照顾安装的需要?

I've tried installing nodejs (which I'm not very familiar with) and included it in the PATH, but the same error happened anyway. Shouldn't maven take care of the need for installing it?

任何有关如何解决此问题的建议都将受到赞赏.

Any advice on how to resolve this is appreciated.

推荐答案

有两种方法可以纠正此问题(如果您同时针对linux和Windows构建项目,则第二种方法是更可取的.此外,如果pom的编号也是文件也很大):

There are two ways to correct this (the second method is preferable if you build the projects targeting linux and windows both. Moreover, also if the no. of pom files is also large):

  1. 如果使用maven,请更改pom文件(请参阅( https://stackoverflow.com/a/40390500/4282901)

           <executions>
            <execution>
              <id>npm install</id>
              <phase>generate-sources</phase>
              <goals>
                 <goal>exec</goal>
              </goals>
              <configuration>
                 <executable>npm.cmd</executable>
                 <arguments>
                    <argument>--loglevel</argument>
                    <argument>error</argument>
                    <argument>install</argument>
                 </arguments>
              </configuration>
           </execution>

  1. 在安装节点的目录中重命名批处理文件,以便选择现有的npm.cmd文件.请参见下面的屏幕截图:
  1. In the directory where node is installed rename the batch file so that the existing npm.cmd file is picked. See screenshot below:

这篇关于Maven无法执行目标-无法运行程序npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆