【问题标题】:How to run a maven webapp with bower in eclipse?如何在eclipse中使用bower运行maven webapp?
【发布时间】:2017-03-17 09:55:12
【问题描述】:

我正在尝试将 bower 集成到我的 maven webapp 中,这是我的 pom.xml 和 bower.json,但我未能下载依赖项。这是我的 pom.xml 和 bower.json 文件。还有一个问题,我需要 nodejs 或 npm 帮助来下载依赖项吗?

bower.json:

{
"name": "Bower1",
"version": "1.0.0",

"description": "javaee7-angular JavaScript dependencies.",
"private": true,
"dependencies": {
    "angular": "1.2.0",
    "jquery": "1.9.1",
    "angular-bootstrap": "0.10.0",
    "angular-grid": "2.0.7"
}

}

pom.xml:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>

    <finalName>Bower1</finalName>
    <plugins>
        <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>
    </plugins>

</build>

【问题讨论】:

  • 感谢您的回复@zillani,但在安装 Bower 时,我收到类似“'node' 未被识别为内部或外部命令、可运行程序或批处理文件”之类的错误。我该如何解决这个问题????
  • np,在下面找到我的答案,如果有帮助请告诉我@Gopi Krishna Seeram

标签: java maven bower bower-install


【解决方案1】:

在 maven eclipse 项目中运行 bower 的分步过程:

1.在本地系统中安装 npm

2.在你的maven中添加以下插件pom.xml&lt;build&gt;&lt;/build&gt;标签

<plugins>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>0.0.20</version>
            <executions>
                <execution>
                    <id>bower install</id>
                    <goals>
                        <goal>bower</goal>
                    </goals>
                    <configuration>
                        <arguments>install</arguments>
                    </configuration>
                </execution>
            </executions>

        </plugin>

    </plugins>

3.在您的webapp根文件夹中添加以下bower.json文件

 {
"name": "BowerTest",
"version": "1.0.0",
"private": true,
"dependencies": {
    "angular": "1.2.0",
    "jquery": "1.9.1",
    "bootstrap":"3.3.7",
    "css":""
}}

4。如果您想添加任何依赖项,请在 dependencies 中添加您的依赖项,如上图所示的 bower.json 文件。

  1. 然后右键单击您的项目单击bower install,安装完成后将在根路径中创建一个文件夹,如bower_components,在那里您可以找到您的依赖项,然后将该依赖项引用到您的视图层中。

【讨论】:

    【解决方案2】:

    Bower 需要 npm(节点包管理器),所以安装 npm 并确保它在你的 PATH 中,

    npm 下载:https://nodejs.org/en/download/

    【讨论】:

    • @zillani...是的,我有 npm,但仍然在 eclipse 中运行该应用程序时遇到同样的错误。所以,请告诉我在 maven webapp 中使用凉亭的总体流程.
    • @GopiKrishnaSeeram 正如您所提到的,您会看到错误,节点'未被识别为内部或外部命令。你给 node -v 看版本了吗?
    • 我当前的node版本是v6.9.5
    猜你喜欢
    • 2015-06-21
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 2016-12-23
    • 2012-12-30
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    相关资源
    最近更新 更多