java 使用 Maven 安装 Bower 组件并全局安装 Bower

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27822050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:26:50  来源:igfitidea点击:

Using Maven to install Bower components with Bower installed globally

javamavenbowerexec-maven-plugin

提问by Tom

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.

我已经使用 NPM 在全球范围内安装了凉亭。在我的 Maven 项目中,我有一个 bower.json 文件,我使用 exec-maven-plugin 在构建时安装 bower 组件,但是它失败了,因为它“无法在目录中运行程序‘bower’”,这是有道理的,因为 Bower未本地安装在项目目录中。

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'.

但是,我想使用 Bower 的全球版本,所以我的所有项目中都没有单独的 Bower 程序,如果我转到终端中的目录并手动运行“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?

问题:我希望 Maven 使用我的全局 Bower 版本,以避免在每个项目中都有重复的 Bower 副本,我该怎么做?

This is the code from my POM file that runs the plugin and execution:

这是我的 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>

采纳答案by Tom

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!

经过大量测试,我发现这是我的 IDE 的问题,出于某种原因,Netbeans 在插件执行期间尝试构建项目时给我一个错误,但是当我直接从命令行运行 Maven 项目时,它建立!

回答by biology.info

don't forget the workingDirectoryand put your bower.json inside root folder

不要忘记workingDirectory并将您的 bower.json 放在根文件夹中

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

回答by fmodos

Configure the executable propertyto point to the full directory of the bower executable, for example:

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

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