java要多思考下

          成長(zhǎng)^_^

             ::  :: 新隨筆 ::  ::  :: 管理 ::
            33 隨筆 :: 0 文章 :: 19 評(píng)論 :: 0 Trackbacks
                  在研發(fā)過程中,會(huì)有許多環(huán)境相關(guān)的配置文件產(chǎn)生。我們的環(huán)境一共有三種:develope,test,product。
          因此在使用maven打包部署的時(shí)候需要將不同環(huán)境的配置文件拷貝到classpath下,以適應(yīng)特定環(huán)境的程序運(yùn)行。
          maven的配置代碼如下:
           1 <plugin>
           2             <groupId>org.apache.maven.plugins</groupId>
           3             <artifactId>maven-antrun-plugin</artifactId>
           4             <version>1.6</version>
           5             <executions>
           6               <execution>
           7                 <id>compile</id>
           8                 <phase>compile</phase>
           9                 <configuration>
          10                   <target>
          11                     <echo message="********************copy profile propertie file *************************"/>                                                                                                                                                                                    
          12                     <copy file="src/main/resources/config/common-product.properties"
          13                           tofile="${buildDirectory}/classes/common.properties" overwrite="true"/>
          14                   </target>
          15                 </configuration>
          16                 <goals>
          17                   <goal>run</goal>
          18                 </goals>
          19               </execution>
          20             </executions>
          21         </plugin>

          另外,有些配置文件如spring/hibernate/mybatis/struts/springmvc/cache等的配置文件也需要復(fù)制到classpath下,
          maven配置如下:

           1 <resources>
           2         <resource>  
           3             <directory>${configSourceDirectory}</directory>
           4             <excludes>  
           5                 <exclude>*.sql</exclude>
           6                 <exclude>common.properties</exclude>
           7                 <exclude>config/*.*</exclude>        
           8             </excludes>  
           9         </resource> 
          10         <resource>  
          11             <directory>${javaSourceDirectory}</directory>
          12             <excludes>  
          13                 <exclude>**/*.java</exclude>    
          14             </excludes>  
          15         </resource>          
          16     </resources> 
          也可使用插件的方式:

           1 <plugin>
           2             <artifactId>maven-resources-plugin</artifactId>
           3             <version>2.5</version>
           4             <executions>
           5               <execution>
           6                 <id>copy-resources</id>
           7                 <phase>validate</phase>
           8                 <goals>
           9                   <goal>copy-resources</goal>
          10                 </goals>
          11                 <configuration>
          12                   <outputDirectory>${buildDirectory}/${fileName}/classes/com/cd/hbm</outputDirectory>
          13                   <resources>          
          14                     <resource>
          15                       <directory>src/main/java/com/cd/hbm</directory>
          16                       <filtering>true</filtering>
          17                     </resource>
          18                   </resources>              
          19                 </configuration>            
          20               </execution>
          21             </executions>
          22           </plugin>

           
          posted on 2013-03-24 02:42 java要多思考下 閱讀(8640) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 平邑县| 土默特右旗| 安阳县| 佛冈县| 莱西市| 深水埗区| 新乡市| 隆子县| 平罗县| 铁岭市| 黑龙江省| 浮梁县| 西畴县| 腾冲县| 荔波县| 金川县| 海口市| 麻江县| 新安县| 临安市| 吴堡县| 长宁县| 绩溪县| 高碑店市| 大田县| 依兰县| 乐业县| 铜山县| 连州市| 隆化县| 望城县| 耿马| 于都县| 洛隆县| 伊春市| 张家港市| 兴山县| 茂名市| 息烽县| 筠连县| 崇左市|