【问题标题】:passing java property file keys via maven command line通过 maven 命令行传递 java 属性文件键
【发布时间】:2017-09-25 20:57:03
【问题描述】:

我在 src/main/java/configs/config.properties 下有一个 config.properties 文件,其中包含以下配置文件:

 <profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <no_of_files>${no_of_files}</no_of_files>
            <no_of_rows>${no_of_rows}</no_of_rows>
        </properties>
    </profile>
</profiles>

我的 config.properties 文件包含

no_of_rows = ${no_of_rows} no_of_files = ${no_of_files}

我正在使用以下 maven 命令通过命令行传递这些属性

mvn exec:java -Dexec.mainClass="com.mycompany.project.App" -Dno_of_rows=4 -Dno_of_files=3

但结果是

[ERROR] Resolving expression: '${no_of_files}': Detected the following recursive expression cycle in 'no_of_files': [no_of_files] @

我在 stackoverflow 上查看了其他类似的答案,但我认为我仍然没有找到正确的方法。

我需要这个来使用竹子作业来运行项目。

【问题讨论】:

    标签: java maven command-line bamboo properties-file


    【解决方案1】:

    你不需要任何 Maven 时髦来做到这一点:

    public class App {
    
        public static void main(String ...args) {
    
            // Load value from -Dno_of_files=
            Integer noOfFiles = Integer.getInteger("no_of_files");
    
            // Load value from -Dno_of_rows=
            Integer noOfRows = Integer.getInteger("no_of_rows");
        }
    
    }
    

    根本不需要 config.properties 和 maven 配置文件。

    如果您真的想将值生成到属性文件中,那么这是一个更复杂的答案。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 2016-04-15
      • 2014-11-05
      • 2012-04-23
      • 1970-01-01
      • 2016-01-12
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多