maven profile

maven profile

1、执行:mvn -P[profile_id]
2、激活activation

< project >
  
  
< profiles >
    
< profile >
      
< id > dev </ id >
      
< activation >
        
< activeByDefault > false </ activeByDefault >
        
< jdk > 1.5 </ jdk >
        
< os >
          
< name > Windows XP </ name >
          
< family > Windows </ family >
          
< arch > x86 </ arch >
          
< version > 5.1.2600 </ version >
        
</ os >
        
< property >
          
< name > mavenVersion </ name >
          
< value > 2.0.5 </ value >
        
</ property >
        
< file >
          
< exists > file2.properties </ exists >
          
< missing > file1.properties </ missing >
        
</ file >
      
</ activation >
      
    
</ profile >
  
</ profiles >
</ project >

3.当使用属性激活的时候
< profiles >
        
< profile >
            
< id > test </ id >
            
< activation >
                
< property >
                    
< name > test.bingo </ name >
                    
< value > kkk </ value >
                
</ property >
            
</ activation >
</ profile >
</ profiles >

可以在命令行中mvn -Dtest.bingo=kkk或者mvn -Ptest这两种方式激活该profile对pom设置的进行覆盖。

4.当使用变量替换的时候
< project  xmlns ="http://maven.apache.org/POM/4.0.0"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
    
    
< build >
        
< resources >
            
< resource >
              
< directory > src/main/filter-resources </ directory >
              
< filtering > true </ filtering >
            
</ resource >
        
</ resources >

    
</ build >
    
< profiles >
        
< profile >
            
< id > test </ id >
            
< activation >
                
< property >
                    
< name > test.bingo </ name >
                    
< value > kkk </ value >
                
</ property >
            
</ activation >
            
< properties >
                
< env .dir > 222 </ env.dir >
            
</ properties >
            
< build >
                        
</ profile >
    
</ profiles >
</ project >

过滤指定的目录下文件,如果该文件中有${env.dir}的变量,就会被222给覆盖掉。

你可能感兴趣的:(maven profile)