maven pom.xml加載不一樣properties配置

1.pom.xmlmysql

===========================
web

<!-- 不一樣的打包環境配置: test=開發/測試測試環境,  product=生產環境; 命令行方式: mvn clean install -Dmaven.test.skip=true -Ptest 或 -Pproduct-->    sql

    <profiles>
       <!-- 開發/測試環境,默認激活 -->
       <profile>
           <id>test</id>
           <properties>
              <env>test</env>
           </properties>
           <activation>
              <activeByDefault>true</activeByDefault><!--默認啓用的是dev環境配置-->
           </activation>
       </profile>
       <!-- 預發佈環境 -->
       <profile>
           <id>preproduction</id>
           <properties>
              <env>preproduction</env>
           </properties>
       </profile>
       <!-- 生產環境 -->
       <profile>
           <id>production</id>
           <properties>
              <env>production</env>
           </properties>
       </profile>
    </profiles>  
 
      <build>
        <filters> <!-- 指定使用的 filter -->
          <filter>src/main/filters/filter-${env}-env.properties</filter>
        </filters>
        <resources>
          <resource> <!-- 配置須要被替換的資源文件路徑, db.properties 應該在 src/main/resource 目錄下 -->
            <directory>src/main/resources</directory>
            <filtering>true</filtering> <!-- 是否使用過濾器 -->
          </resource>
        </resources>
maven

      </build>測試


2.src/main/filters/下不一樣環境的配置文件ui

src/main/filters/filter-preproduction-env.propertiesurl

src/main/filters/filter-production-env.propertiesspa

src/main/filters/filter-test-env.properties插件

======filter-test-env.properties 舉例
命令行

jdbc.url=jdbc:mysql://192.168.120.220:3306/testdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=testuser
jdbc.password=123456


3.src/main/resources下要應用處理的文件

src/main/resources/conf/db.properties

======db.properties

jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}

jdbc.minPoolSize=10
jdbc.maxPoolSize=50
jdbc.autoCommit=false






¥¥¥¥¥¥¥¥

 A.pom.xml屬性介紹:

                     project: pom的xml根元素。

                     parent:  聲明繼承。

                     modules:  聲明聚合,該值是一個當前POM的相對目錄。用戶項目的聚合。

                     groupId:  定義當前Maven項目隸屬的實際項目。

                     artifactId:  定義實際項目中的一個Maven項目模塊,通常爲實際項目名稱。

                     version:  定義Maven項目當前版本。

                     groupId、artifactId、version三個屬性構成項目的座標,必須所有填寫。

                     packaging: 座標元素之一,能夠不填,不填默認jar,表示項目構建成jar包;值爲war表示可部署的web項目。

                     name: 名稱。

                     description: 項目描述。

                     organization: 所屬組織。

                     licenses: 許可證。

                     mailingLists: 郵件列表。  

                     developers: 開發者。

                     contributors: 貢獻者。

                     issueManagement: 問題追蹤系統。

                     ciManagement: 持續集成系統。

                     scm: 版本控制系統。

                     prerequisites-->maven: 要求maven最低版本,默認值爲2.0.

                     build-->sourceDirectory: 主源碼目錄。

                     build-->scriptSourceDirectory: 腳本源碼目錄。

                     build-->testSourceDirectory: 測試源碼目錄。

                     build-->outputDirectory: 主源碼輸出目錄。

                     build-->testOutputDirectory: 測試源碼輸出目錄。

                     build-->resources-->resource:  主資源目錄。

                     build-->testResources-->testResource: 測試資源目錄。

                     build-->finalName: 輸出主構件的名稱。

                     build-->directory: 輸出目錄。

                     build-->filters-->filter: 經過properties文件定義資源過濾屬性。

                     build-->extensions-->extension: 擴展Maven的核心。

                     build-->pluginManagement:  插件管理。

                     build-->plugins-->plugin: 插件。

                     profiles-->profile: POM Profile。

                     distributionManagement-->repository: 發佈版本部署倉庫。

                     distributionManagement-->snapshotRepository: 快照版本部署倉庫。

                     distributionManagement-->site: 站點部署。

                     repositories-->repository: 倉庫。

                     pluginRepositories-->pluginRepository:  插件倉庫。

                     dependencies-->dependency: 依賴管理。

                     properties: Maven屬性。

                     reporting-->plugins: 報告插件。

                    a-->b表示a元素嵌套着b元素。

 

         B.settings.xml文件配置。 

                    settings: settings.xml的根元素。

                    localRepository: 本地倉庫。

                    interactiveMode: Maven是否與用戶交互,默認值爲true。

                    offline: 離線模式,默認false。

                    pluginGroups-->pluginGroup: 插件組。

                    servers-->server: 下載與部署倉庫的認證信息。

                    mirrors-->mirror: 倉庫鏡像。

                    proxies-->proxy: 代理。

                    profiles-->profile: Settings Profile。

                    activeProfiles-->activeProfile: 激活Profile。

                    Maven目錄下的conf文件夾下的settings.xml爲全局的,影響全部用戶的配置。通常建議修改c:\Users\用戶名\.m2\目錄下的settings.xml,屬於局部的,只對當前目

         錄下的用戶有用。

相關文章
相關標籤/搜索