【问题标题】:want to run exec-maven-plugin when spring-boot running想在 spring-boot 运行时运行 exec-maven-plugin
【发布时间】:2017-08-02 08:59:47
【问题描述】:

我的 Spring-boot 项目结构如下 -Project - src - main - java - resources - webapp - test - frontend - src - static - config - package.json - (after "npm install") node_modules - (after "npm run build") dist

我想做的是

  1. 安装项目后,运行“npm install”

  2. 当“spring-boot:run”运行时,运行“npm run build”并将front/dist中的内容移动到/main/webapp

这是我的 pom.xml

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

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>exec-npm-install</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <executable>npm</executable>
                        <workingDirectory>./frontend</workingDirectory>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </pluginManagement>
</build>

我不知道如何触发 exec-npm-install 执行 使用 Eclipse maven 构建,我尝试了 generate-sources、spring-boot:run、安装和编译、打包但它没有运行。

我想知道我应该放什么命令,在“spring-boot:run”时移动dist

【问题讨论】:

  • 您需要将其移出插件管理区域。在 pluginManagement 中,您可以定义版本和参数,但您需要将其放在 pluginManagement 之外。
  • 谢谢。在Eclipse中,没有pluginManagement,执行会出现错误信息,所以我把它们放在里面。现在,正如您的评论,我删除了 pluginManagement 并忽略了执行错误。它有效!
  • 你得到什么样的执行错误?

标签: maven spring-boot exec-maven-plugin


【解决方案1】:

几件事 -

  • 正如@khmarbaise 所指出的,您应该将&lt;plugins&gt; 树移出&lt;pluginManagement&gt;,并为您正在使用的插件使用&lt;version&gt;

  • 我不知道如何触发 exec-npm-install 执行

由于执行与执行的generate-sources 阶段相关联。如果您尝试从项目目录的命令行中执行mvn generate-sources,您将触发执行。还执行mvn testmvn installmvn package 应该是必要的。看看这个Maven - Lifecycle Reference

  • 我想知道我应该放什么命令,在什么时候移动 dist “弹簧启动:运行”

如果你想将资源复制到/webapp目录,你应该看看maven-resources-plugin并相应地改变它的阶段。

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 2018-11-12
    • 2018-07-15
    • 2012-03-03
    • 2016-01-31
    • 1970-01-01
    • 2014-04-19
    • 2018-05-06
    • 2013-07-01
    相关资源
    最近更新 更多