如何在eclipse中使用bower运行maven webapp?

时间:2017-03-17 09:55:12

标签: java maven bower bower-install

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

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>

2 个答案:

答案 0 :(得分:3)

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

1.在本地系统中安装npm

2.在您的专家pom.xml <build></build>代码中添加以下插件

<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.在bower.json根文件夹

中添加以下webapp文件
 {
"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,您可以在其中找到您的依赖项,然后将这些依赖项引用到您的视图层。 / LI>

答案 1 :(得分:0)

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

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