验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

如何掌握maven  filtering标签

阅读:627 来源:乙速云 作者:代码code

如何掌握maven  filtering标签

filtering的作用

MAVEN提供了一种过滤机制,这种机制能够在资源文件被复制到目标目录的同时,当filtering = true时替换资源文件中的占位符;当filtering = false时不进行占位符的替换。

1.(方式一)首先在pom.xml文件中做出以下添加: 


 
    HelloWorld
 
    
        
            
                src/main/resources
                true
            
        
    
 

filtering:开启过滤,用指定的参数替换directory下的文件中的参数(eg. ${name})

directory:指定资源文件的位置。

mvn resources:resources :对资源做出处理,先于compile阶段。

2. 然后在src/main/resources下,添加一个文件,比如叫test.txt。test.txt内容如下:

I want to say : ${name}

3.执行 mvn resources:resources 命令,最后会在target/classes下看到test.txt的内容变成了,如下所示:

I want to say : HelloWorld

方式二. 同样先在pom.xml添加如下:


 
    HelloWorld
    
    
        Tom
    
 
    
        
            
                src/main/resources
                true
            
        
    
 

然后在test.txt,添加一句: 

My name is ${username}

再执行上述的步骤3。即可变成: My name is Tom

方式三:


 
    
        src/main/resources/code.properties
    
 
    
        
            
                src/main/resources
                true
            
        
    
 

在src/main/resources下添加文件code.properties

该文件内容如下:

username1=tom1
password=123

然后test.txt,添加如:${username1}  ${password} 执行步骤3,也会得到同样的效果。

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>