无法在目录中运行程序"npm"

Ach*_*yut 13 maven node.js gruntjs

当我遍历到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]
Run Code Online (Sandbox Code Playgroud)

这是一台Windows机器.

Mos*_*roy 11

我使用此解决方法来实现跨平台的Maven构建:将npm可执行文件名称声明为Maven变量,并在Windows上运行时使用Maven过滤器修改此可执行文件名称.

它可以用于Grunt,Bower等.

如果你使用exec-maven-plugin> = 1.6.0(感谢Manmay的评论中的信息),这个解决方法就不再需要了:这是这个插件的一个bug(参见https://github.com/mojohaus/) exec-maven-plugin/issues/42),已在1.6.0中修复(参见https://github.com/mojohaus/exec-maven-plugin/pull/46)

<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>
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用的是插件版本 1.6.0,则无需更改任何内容 (2认同)

小智 6

在Windows平台中,使用npm.cmd替换npm

  • 这将导致非 Windows 操作系统上的构建中断,如何解决此问题以成为操作系统**独立**? (2认同)

Rag*_*ram 4

显然你使用的是Windows系统。npm 是一个批处理文件,而不是可执行文件。从 Maven exec 插件运行批处理文件时出现问题。您可能想探索链接中建议的解决方法,例如

  • 将 .bat 脚本解构为其实际命令
  • 使用 cmd.exe 并传递节点作为参数 -请参阅此


归档时间:

查看次数:

26461 次

最近记录:

7 年,2 月 前