使用Maven安装已全局安装Bower组件的Bower组件

4
我已经使用NPM全局安装了Bower。在我的Maven项目中,我有一个bower.json文件,我正在使用exec-maven-plugin在构建时安装bower组件,但它失败了,因为它“无法在目录中运行程序‘bower’”,这是有道理的,因为Bower没有在项目目录中本地安装。
然而,我想使用全局版本的Bower,这样我就不需要在所有项目中都有独立的Bower程序了。如果我在终端中进入目录并手动运行“bower install”,它可以工作。
问题:我想Maven使用我的全局Bower版本,以避免在每个项目中拥有重复的Bower副本,我该怎么做?
这是我POM文件中运行插件和执行的代码:
 <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>
3个回答

2
不要忘记工作目录,并将你的文件放在根目录中。
<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>

我遇到了这个错误:env: node: No such file or directory,似乎与node的配置有关...(我猜测)然而我已经全局安装了node和bower,但我甚至没有使用node,那为什么会出现这个问题呢? - Tom
注意:bower.json 必须在 ${basedir}/src/main/webapp 内。 - Benny Code

2

经过大量测试,我发现问题出在我的IDE上,不知何故Netbeans在插件执行期间尝试构建项目时会给我一个错误,但是当我直接从命令行运行Maven项目时,它可以成功构建!


1

可执行属性配置为指向bower可执行文件的完整目录,例如:

 <executable>c:/bower_directory/bower</executable>

不起作用,我已经尝试使用:<executable>/Mavericks/usr/local/lib/node_modules/bower/bin/bower</executable>,它给了我“命令执行失败。无法运行程序“/Mavericks/usr/local/lib/node_modules/bower/bin/bower” ”和 <executable>/usr/local/lib/node_modules/bower/bin/bower</executable>,它给了我“命令执行失败。进程退出错误:127”,但是如果我去终端并运行 /usr/local/lib/node_modules/bower/bin/bower,通常的 bower 消息会显示。 - Tom

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接