美文网首页
在properties文件中获取maven pom的versio

在properties文件中获取maven pom的versio

作者: f07bfe4a10fd | 来源:发表于2016-07-31 14:56 被阅读1626次

其实maven已经给出了方案, 就是在资源文件(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
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>
  1. 执行mvn package
    查看生成的jar文件中的application.properties, version值已经变成了pom.xml中的version

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

相关文章

网友评论

      本文标题:在properties文件中获取maven pom的versio

      本文链接:https://www.haomeiwen.com/subject/edwydttx.html