gpt4 book ai didi

java - 无法使用 Maven 运行 npm grunt bower

转载 作者:行者123 更新时间:2023-11-29 08:42:34 25 4
gpt4 key购买 nike

我有一个使用 npm bower 和 grunt 的简单网络应用程序。我将这个项目用作 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?

最佳答案

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

您仍然可以使用 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>

这应该有效。

关于java - 无法使用 Maven 运行 npm grunt bower,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38981660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com