如何使用pom.xml通过命令行更新属性文件

时间:2017-04-03 12:38:18

标签: spring maven command-line-interface pom.xml properties-file

这是我添加此变量的属性文件 的 databaseEnabled = $ {db.activedb}

我的属性文件的路径 的的src /主/资源/ application-dev.properties

这是我添加此代码的pom.xml

<build>
    <finalName>spring-boot</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>dynamo</id>
        <activation>
            <property>
                <name>env</name>
                <value>dynamo</value>
            </property>
        </activation>
        <properties>
            <db.activedb>dynamodb</db.activedb>
        </properties>
    </profile>
    <profile>
        <id>mongo</id>
        <activation>
            <property>
                <name>env</name>
                <value>mongo</value>
            </property>
        </activation>
        <properties>
            <db.activedb>mongodb</db.activedb>
        </properties>
    </profile>
</profiles>

1 个答案:

答案 0 :(得分:0)

添加includes代码:

<resource>
    <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>/application-dev.properties</include>
        </includes>
    </resource>
</resource>

使用-P选项设置个人资料:

mvn package -P mongo

检查结果打开target/classes/application.properties文件。