我有一个简单的web应用程序,使用npm bower和grunt。我使用这个项目作为一个maven项目的模块。我搜索了互联网,发现如何为项目定义pom.xml,但我无法运行它。谁能告诉我如何使用maven构建和运行web应用程序的步骤?
文件
<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 Filesnodejsnpm" (in directory "C:UserskrsIdeaProjectsproject"): 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>