java要多思考下

          成長(zhǎng)^_^

             ::  :: 新隨筆 ::  ::  :: 管理 ::
            33 隨筆 :: 0 文章 :: 19 評(píng)論 :: 0 Trackbacks
                  在研發(fā)過(guò)程中,會(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要多思考下 閱讀(8642) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 普兰店市| 奉节县| 延边| 东明县| 木里| 南木林县| 崇左市| 革吉县| 鄂伦春自治旗| 宁国市| 沐川县| 罗定市| 贞丰县| 德钦县| 垫江县| 卫辉市| 封开县| 高邮市| 新密市| 社会| 玉龙| 周口市| 汾阳市| 手游| 茶陵县| 和硕县| 百色市| 凤城市| 彭州市| 清徐县| 阜阳市| 清镇市| 温泉县| 扎赉特旗| 兴义市| 大足县| 康定县| 迭部县| 称多县| 台江县| 惠东县|