krs8888 krs8888 - 3 months ago 103
AngularJS Question

cannot run npm grunt bower using maven

I have a simple web application that uses npm bower and grunt. I am using this project as a module in a maven project. I searched the internet and found how to define the pom.xml for the project but I am not able to run it. Can anyone tell me the steps on how to build and run the webapp using maven.

the 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>


The error that I am getting is

[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


How to build and run this pom using maven ?

Answer

The reason why you can't run it is because it's not an executable, it's a batch file or shell script if you're not on windows.

You can still use maven exec plugin to run it. However to do that you'll have to feed the batch file npm to cmd program (or bash or whatever is your favorite shell).

Following is the change that you'll need to make.

Actual command to feed batch to cmd

cmd /c "npm --version"

Following is the change in the plugin configuration.

<configuration>
  <executable>cmd</executable> <!-- or bash -->
  <workingDirectory>./</workingDirectory>
  <arguments>
    <argument>/c</argument>
    <argument>"npm --version"</argument>
  </arguments>
</configuration>

This should work.

Comments