Using Maven to install Bower components with Bower installed globally
Solution 1
After a lot of testing, I've figured out it was a problem with my IDE, for some reason Netbeans gives me an error when it tries to build the project during the plugin execution, however when I run the Maven project straight from command line, it builds!
Solution 2
don't forget the workingDirectory and put your bower.json inside root folder
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>bower</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
</configuration>
</plugin>
Solution 3
Configure the executable property to point to the full directory of the bower executable, for example:
<executable>c:/bower_directory/bower</executable>
Tom
Updated on June 09, 2022Comments
-
Tom almost 2 years
I have bower installed globally using NPM. In my Maven project I have a bower.json file, I am using the exec-maven-plugin to install the bower components on build, however it failed because it "cannot run the program 'bower' in directory" which makes sense because Bower is not locally installed in the project directory.
However I want to use the global version of Bower so I don't have separate Bower programs in all my projects, it works if I go to the directory in terminal and manual run 'bower install'.
Question: I want Maven to use my global Bower version to avoid me having duplicate copies of Bower in each project, how do I do this?
This is the code from my POM file that runs the plugin and execution:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <executions> <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> </executions> </plugin>
-
Tom over 9 yearsDoesn't work, I've tried using:
<executable>/Mavericks/usr/local/lib/node_modules/bower/bin/bower</executable>
which gives me Command execution failed. Cannot run program "/Mavericks/usr/local/lib/node_modules/bower/bin/bower" and<executable>/usr/local/lib/node_modules/bower/bin/bower</executable>
which gives me Command execution failed. Process exited with an error: 127, however if I go to terminal and run/usr/local/lib/node_modules/bower/bin/bower
the usual bower message shows -
Tom over 9 yearsI'm no getting this error:
env: node: No such file or directory
which is to do with node configurations... (i'm guessing) however I have node installed globally as is bower, but i'm not even using node so why does it matter? -
Benny Neugebauer about 9 yearsNote:
bower.json
has to be inside${basedir}/src/main/webapp
.