如何从属性文件将值注入pom.xml

时间:2019-01-23 11:20:35

标签: java maven

我需要从属性文件中自定义pom.xml。我正在尝试将值(project.name,version)注入我的pom.xml 我需要在pom.xml中进行什么更改才能读取然后注入这些属性

这是我的财产文件:

project.name=example1
version=2.7.0

这是我的pom.xml

<build>
    <finalName>${project.name}</finalName>
    <sourceDirectory>src</sourceDirectory>
    <scriptSourceDirectory>src/scripts</scriptSourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>

    <resources>
        <resource>
            <directory>src/resources</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>${basedir}/scripts/local.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>cl2</groupId>
        <artifactId>example</artifactId>
        <version>${version}</version>
        <scope>system</scope>
        <systemPath>${basedir}/example/path</systemPath>
    </dependency>
</dependencies>

0 个答案:

没有答案