Maven: 如何在properties文件中获取maven的 pom.xml 的键值

阅读更多

  原文链接:http://blog.csdn.net/bigtree_3721/article/details/51898095

 

 

如何在properties文件中获取maven的 pom.xml 的键值?
答案就是:在资源文件(*.properties)中放置pom.xml预先设置的变量, 在执行mvn package时就会自动将变量替换为真实值
例如:
1. 我们在src\main\resources\application.properties放置如下内容
     version=${project.version}
2. 配置pom.xml让Maven to copy that file into your output classes and translate the resource during that copy, interpreting the property
    
        
            
                src/main/resources
                true
            
        
    
3. 执行mvn package
    查看生成的jar文件中的application.properties, version值已经变成了pom.xml中的version

因此我们只需使用java读取application.properties即可

你可能感兴趣的:(maven,pom.xml,properties)