有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从pom的属性文件中读取属性。xml

我有一些配置会根据项目部署到的环境进行更改。我正在考虑将属性文件添加到src/resources,DevOps可以在部署项目时编辑该文件。我需要pom.xml文件来读取这些属性。有办法吗


共 (1) 个答案

  1. # 1 楼答案

    你不需要属性文件。您可以在POM本身的<profiles>中声明属性,并交替激活这些属性。见Maven / Introduction to build profiles

    A profile can be activated in several ways:

    • ...

    Profiles specified in the POM can modify the following POM elements:

    • ...
    • <properties>

    [...] Note that too many files to configure is very confusing and very hard to maintain. Bottom line is that since this is build data, it should be in the POM. One of the goals in Maven 2 is to consolidate all the information needed to run a build into a single file, or file hierarchy which is the POM.