概述
Retrieve version from maven pom.xml in code
Assuming you're using Java, you can
-
Create a .properties file in (most commonly) your src/main/resources directory (but in step 4 you could tell it to look elsewhere).
-
Set the value of some property in your .properties file using the standard Maven property for project version: foo.bar=${project.version}
-
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).
-
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所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复