maven的profile 目录、变量打包

<project>

 <build>
    <finalName>maven-project</finalName>
    <resources>  
       <resource>  
           <directory>src/main/resources</directory>
            <!--资源根目录排除各环境的配置,使用单独的资源目录来指定   -->
           <excludes>
               <exclude>dev/*</exclude>
               <exclude>prd/*</exclude>
           </excludes>
          <filtering>true</filtering>
       </resource>
       <resource>
           <directory>src/main/resources</directory>           
            <!-- 包含,若没有指定则默认为 activeByDefault 标签定义的profile -->  
            <includes>  
                <include>${profiles.active}/*</include>  
            </includes>  
           <filtering>true</filtering>
       </resource>
    </resources>  
  </build>
  
    <profiles>
        <profile>
            <!-- 本地开发环境 -->
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
                   <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
                <jdbc.url>jdbc:mysql://localhost:3306/dev</jdbc.url>
                <jdbc.username>root_dev</jdbc.username>
                <jdbc.password>123456_dev</jdbc.password>
                <jdbc.maxActive>5</jdbc.maxActive>
                <deploy.url>http://host:port/manager/text</deploy.url>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 生产环境 -->
            <id>prd</id>
            <properties>
                <profiles.active>prd</profiles.active>
                   <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
                <jdbc.url>jdbc:mysql://localhost:3306/prd</jdbc.url>
                <jdbc.username>root_prd</jdbc.username>
                <jdbc.password>123456_prd</jdbc.password>
                <jdbc.maxActive>5</jdbc.maxActive>
                <deploy.url>http://host:port/manager/text</deploy.url>
            </properties>
        </profile>
    </profiles>
</project>

jdbc.properties

jdbc.driver=${jdbc.driver}
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.maxActive=${jdbc.maxActive}

posted on 2017-09-13 17:08  web369  阅读(246)  评论(0编辑  收藏  举报

导航