通过maven命令行传递java属性文件密钥

时间:2017-04-27 21:38:35

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

我在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上查看了其他类似的答案,但我认为我仍然没有找到正确的方法。

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

1 个答案:

答案 0 :(得分:1)

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

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配置文件。

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