如何使用Maven启动“bower install”然后“spring-boot:run”?

时间:2017-07-06 14:12:26

标签: maven intellij-idea spring-boot bower-install

我是一名研究员,我在项目中对Maven并不了解。

我在同一个存储库中使用spring-boot和angular 1,我需要一个解决方案,在使用maven插件“spring-boot:run”之前先执行“bower install”。

我想知道是否可以自定义maven命令。

我使用IntelliJ,我所做的就是按下主课程中的开始按钮

package fr.studionline;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAutoConfiguration
public class StudionlineBackApplication {

    public static void main(String[] args) {
        SpringApplication.run(StudionlineBackApplication.class, args);
    }
}

bower_components目录位于主类之外的另一个目录中,如下图所示: tree view of my project

如果您能帮助我了解它的工作原理,请提前致谢。

如果我的问题中缺少某些内容,我会回答任何问题。

更新

我尝试使用此pom配置的前端maven插件:

<build>
        <resources>
            <resource>
                <directory>src/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <!-- Use the latest released version:
                https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
                <version>1.4</version>


                <executions>
                    <execution>
                        <id>bower install</id>
                        <goals>
                            <goal>bower</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <workingDirectory>src/main/resources/static</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

这就是我执行命令frontend时发生的事情:bower

[INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building studionline-back 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- frontend-maven-plugin:1.4:bower (default-cli) @ studionline-back ---
    [INFO] Running 'bower install' in C:\Antoine\Ecole\Projet\ProjetAnu_5A\studionline-back\src\main\resources\static
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.071 s
    [INFO] Finished at: 2017-07-06T17:59:58+02:00
    [INFO] Final Memory: 11M/155M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-

    plugin:1.4:bower 
    (default-cli) on project studionline-back: Failed to run task: 'bower install' failed. 
    java.io.IOException: 

Cannot run program "C:\Antoine\Ecole\Projet\ProjetAnu_5A\studionline-back\src\main\resources\static\node\node.exe" 
(in directory "C:\Antoine\Ecole\Projet\ProjetAnu_5A\studionline-back\src\main\resources\static"): 

    CreateProcess error=2, Le fichier spécifié est introuvable -> [Help 1]

    [ERROR] 

    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

    [ERROR] Re-run Maven using the -X switch to enable full debug logging.

    [ERROR] 

    [ERROR] For more information about the errors and possible solutions, please read the following articles:
        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

        Process finished with exit code 1

但我仍然不明白如何使用Intellij启动它。我应该运行mvn而不是单击“运行”按钮吗?

1 个答案:

答案 0 :(得分:1)

查看<execution> <id>bower install</id> <goals> <goal>bower</goal> </goals> <configuration> <!-- optional: The default argument is actually "install", so unless you need to run some other bower command, you can remove this whole <configuration> section. --> <arguments>install</arguments> </configuration> </execution> 。特别是它有一个bower runner

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>

    <!-- optional -->
    <configuration>
        <workingDirectory>src/main/resources/static</workingDirectory>
    </configuration>
</plugin>

检查“可选配置”部分以了解如何配置前端目录。在你的情况下:

console.log(request);