总结:Maven之exec-maven-plugin

一、介绍

如果你想在项maven生命周期内,运行一段java代码,或者一段独立的程序,或者说我们所指的预执行,初始化某些值,生成某些不能预先生成的文件。 那么这样我们就可以使用exec-maven-plugin进行程序的预执行,生成相关文件。

二、配置案例

<plugin>
      	<groupId>org.codehaus.mojo</groupId>
	  	<artifactId>exec-maven-plugin</artifactId>
	  	<version>1.6.0</version>
	  	<executions>
	  		<execution>
		      <id>git-info</id>
		      <phase>exec</phase>
		      <goals>
			      <goal>exec</goal>
		      </goals>
              <configuration>
                <executable>${project.basedir}/build_info.sh</executable>
                <outputFile>${project.basedir}/src/main/webapp/build.info</outputFile>
              </configuration>
	      </execution>
          <execution>
		      <id>gen-version</id>
		      <phase>exec</phase>
		      <goals>
			      <goal>exec</goal>   <!-- java还是exec-->
		      </goals>
              <configuration>
                <executable>${project.basedir}/gen_version.sh</executable>
                <outputFile>${project.basedir}/VERSION</outputFile>
              </configuration>
	      </execution>
          <execution>
            <id>gen-cron-props</id>
            <phase>exec</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>sed</executable>
              <arguments>
                <argument>s/environment=product/environment=product_cron/g</argument>
                <argument>${project.basedir}/profile/env.product.properties</argument>
              </arguments>
              <outputFile>${project.basedir}/profile/env.product_cron.properties</outputFile>
            </configuration>
          </execution>
      	</executions>
      </plugin>

三、使用

mvn exec:exec@gen-version exec:exec@git-info clean package -DAPP_ENV=test -Dmaven.test.skip=true

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值