maven war多環境對應

web項目文件替換(src/main/portable/dev.xml)mysql

<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
src/main/resource/redis/redis.properties
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完成文件替換web

<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>
相關文章
相關標籤/搜索