不能 运行 npm g运行t bower 使用 maven

cannot run npm grunt bower using maven

我有一个使用 npm bower 和 g运行t 的简单 Web 应用程序。我将这个项目用作 Maven 项目中的模块。我在互联网上搜索并找到了如何为项目定义 pom.xml,但我无法 运行。谁能告诉我如何使用 maven 构建和 运行 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 构建和 运行 这个 pom?

你不能 运行 的原因是因为它不是可执行文件,它是批处理文件或 shell 脚本,如果你不在 windows。

您仍然可以使用 maven exec 插件 运行 它。但是,要做到这一点,您必须将批处理文件 npm 提供给 cmd 程序(或 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>

这应该有效。