1

In my java webapp project I have all the jsp files placed at src/main/webapp/jsp. How do I enable the filtering and replace property placeholders with actual values while building the war?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <filters><filter>${basedir}/src/main/resources/filter.properties</filter></filters>
        <webResources>
            <resource>
                <directory>src/main/webapp/jsp</directory>
                <targetPath>/jsp/</targetPath>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
</plugin>

Attaching the console output of mvn package command :

[exec] [INFO] Copying webapp webResources [projectbasedir/src/main/webapp/jsp] to [projectbasedir/target/myapp]
[exec] [INFO] Copying webapp resources [projectbasedir/src/main/webapp]

The jsp files are getting filtered properly in "Copying webapp webResources" step but "Copying webapp resources" step overwrites all these changes since it copies everything from src/main/webapp folder to target folder afresh.

How do I make this filtering work?

TechnoCrat
  • 2,055
  • 4
  • 23
  • 35
  • possible duplicate of [Files got overwritten in maven project when building a war](http://stackoverflow.com/questions/10133485/files-got-overwritten-in-maven-project-when-building-a-war) – TechnoCrat Jan 07 '15 at 10:17
  • Can you post the resource configuration you have? – Willa Mar 17 '16 at 13:41

1 Answers1

0

Try to replace it with this config, the difference is to use directory as src/main/webapp and include subfolder in includes. For whatever reasons when directory matches with warSourceDirectory it works fine.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <filters><filter>${basedir}/src/main/resources/filter.properties</filter></filters>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>/jsp/</targetPath>
                <filtering>true</filtering>
                <includes>
                    <include>jsp/**</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>
iamandrewluca
  • 3,411
  • 1
  • 31
  • 38