我是靠谱客的博主 酷炫硬币,最近开发中收集的这篇文章主要介绍JAVA代码中获取maven pom.xml信息 Retrieve version from maven pom.xml in code,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Retrieve version from maven pom.xml in code


Assuming you're using Java, you can

  1. Create a .properties file in (most commonly) your src/main/resources directory (but in step 4 you could tell it to look elsewhere).

  2. Set the value of some property in your .properties file using the standard Maven property for project version: foo.bar=${project.version}

  3. In your java code, load the value from the properties file as a resource from the classpath (google for copious examples of how to do this).

  4. In Maven, enable resource filtering - this will cause Maven to copy that file into your output classes and translate the resource during that copy, interpreting the property. You can find some info herebut you mostly just do this in your pom:

    <build>
      <resources>
        <resource>
          <directory>src/main/resources</directory>
          <filtering>true</filtering>
        </resource>
      </resources>   
    </build>

You can also get to other standard properties like project.name, project.description, or even arbitrary properties you put in your pom etc. Resource filtering, combined with Maven profiles, can you give variable build behavior at build time. When you specify a profile at runtime with -PmyProfile that can enable properties that then can show up in your build.


最后

以上就是酷炫硬币为你收集整理的JAVA代码中获取maven pom.xml信息 Retrieve version from maven pom.xml in code的全部内容,希望文章能够帮你解决JAVA代码中获取maven pom.xml信息 Retrieve version from maven pom.xml in code所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部