简体   繁体   中英

Maven resource filtering not working on Spring configuration XML file wiith tests

I am trying to add some filtering to the Spring application context file, which resides in src/main/resources folder but it's not working. I put my filter file in src/main/filters

I've tried many solutions but none are working when i launch unit test through maven install or junit but if i skip test it's filtering it's working .

I've modified the file .classPath , I removed exclude attribute from the file edit classpath solution then I read this article bug in maven-resources-plug who said that there is a bug in maven-resources-plugin so I updated the plugin to a newer version but it's still not working.

My pom.xml :

<build>
    <finalName>core-impl</finalName>

    <directory>target</directory>
    <sourceDirectory>src/main/java</sourceDirectory>
    <outputDirectory>target/classes</outputDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <testOutputDirectory>target/test-classes</testOutputDirectory>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <filters>
        <filter>src/main/filters/filter.properties</filter>
    </filters>

</build>

i tried this solution and it's working .

<execution>
        <id>default-resources</id>
            <phase>process-resources</phase>
        <goals>
            <goal>resources</goal>
        </goals>
        <configuration>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <filters>
                <filter>${basedir}/src/main/filters/filter.properties</filter>
            </filters>
        </configuration>
</execution>
<execution>
        <id>default-testResources</id>
            <phase>process-test-resources</phase>
        <goals>
            <goal>resources</goal>
        </goals>
        <configuration>
            <resources>
                <resource>
                    <directory>src/test/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <filters>
                <filter>${basedir}/src/test/filters/filter.properties</filter>
            </filters>
        </configuration>
</execution>
<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
</resource>
</resources>

<testResources>
    <testResource>
        <filtering>true</filtering>
        <directory>src/test/resources</directory>
    </testResource>
</testResources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM