maven war多环境对应

web项目文件替换(src/main/portable/dev.xml)

<portable-config>
    <config-file path="WEB-INF/classes/Application.properties">
            <replace key="connection.url">jdbc:mysql://localhost:3306/dbname?zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true&amp;useUnicode=true&amp;characterEncoding=utf-8</replace>
            <replace key="connection.username">xxxxxx</replace>
            <replace key="connection.password">yyyyyy</replace>
     </config-file>
     <config-file path="WEB-INF/classes/spring-jms.xml">
            <replace xpath="/beans/bean[@id='jmsConnectionFactory']/property[@name='brokerURL']/@value">tcp://localhost:61616</replace>
            <replace xpath="/beans/bean[@id='jmsConnectionFactory']/property[@name='userName']/@value">xxxxxxx</replace>
            <replace xpath="/beans/bean[@id='jmsConnectionFactory']/property[@name='password']/@value">yyyyy</replace>
        </config-file>
</portable-config>
<plugin>
    <groupId>com.juvenxu.portable-config-maven-plugin</groupId>
    <artifactId>portable-config-maven-plugin</artifactId>
    <version>1.1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>replace-package</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <portableConfig>src/main/portable/${package.environment}.xml</portableConfig>
    </configuration>
</plugin>
<?xml version="1.0" encoding="utf-8" ?>
<portable-config>
    <config-file path="jdbc.properties">
        <replace key="jdbc.url">www.zzn.com.cn</replace>
        <replace key="username">xxxxxx</replace>
        <replace key="password">yyyyyy</replace>
    </config-file>
    <config-file path="redis/redis.properties">
       <replace key="redis.host">192.168.0.1</replace>
       <replace key="redis.port">6379</replace>
       <replace key="redis.password">123456</replace>
    </config-file>
</portable-config>
resources/jdbc.properties
-------------------------------------
jdbc.driver=orcle
jdbc.url=localhost
username=test
password=test
redis.host=127.0.0.1
redis.port=6379
redis.password=123456

 

<profiles>
    <profile>
        <id>product</id>
        <properties>
            <package.environment>product</package.environment>
        </properties>
    </profile>
    <profile>
        <id>dev</id>
        <properties>
            <package.environment>dev</package.environment>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
</profiles>

用ant完成文件替换

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
          <delete file="${project.build.outputDirectory}/environment.properties"/>
          <copy file="src/main/resources/environment.test.properties"
                tofile="${project.build.outputDirectory}/environment.properties"/>
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>

 

转载于:https://my.oschina.net/u/1453451/blog/506925

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值