java要多思考下

成长^_^

   ::  :: 新随笔 ::  ::  :: 管理 ::
  31 随笔 :: 0 文章 :: 19 评论 :: 0 Trackbacks
        在研发过程中,会有许多环境相关的配置文件产生。我们的环境一共有三种:develope,test,product。
因此在使用maven打包部署的时候需要将不同环境的配置文件拷贝到classpath下,以适应特定环境的程序运行。
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等的配置文件也需要复制到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要多思考下 阅读(7898) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: