maven 使用filter动态处理资源文件变量

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mylab.maven</groupId>
    <artifactId>filter-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <filters>
            <filter>${basedir}/profiles/helloFilter.txt</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>hello.txt</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>

helloFilter.txt:

name = world

hello.txt:

Hello ${name}

运行: mvn clean compile

结果:  cat hello.txt --> Hello world


你可能感兴趣的:(maven)