I wasn't able to figure out how to do simple exclude filtering of files under my src/main/webapp directory by looking at the current usage examples on the maven war plug-in page. This simple tutorial describes how to use the warSourceExcludes tag to perform this task. [ Suggestion: the official documentation page for maven:war plugin could use a how-to example along the lines of what I present below].
Sometimes you want to filter out stuff in your war file that want to use for development and testing, but don't want to have included in your production environment. An example is deployment environment specific properties files that you want to have on your classpath, but not in your .war (so that an adminstator can twiddle the properties without cracking open your .war).
Here's an example of how to this.
- Create a simple web application using maven archetype:
- mvn archetype:generate -DarchetypeGroupId=org.codehaus.groovy.maven.archetypes -DgroupId=com.foo -DartifactId=example -Dpackage=com.lackey
- choose option 18 (simple web app -- this will generate a simple web app project).
- cd example
- create a file src/main/webapp/server.properties
- run: mvn package
- notice you have a file target/example/server.properties -- this means server.properties will end up in your .war.
- now change your pom file to include the following directives in the <build> block:
- run: mvn package (again)
notice the file target/example/server.properties is no longer present. You can check the .war as well, it won't be there, which is what you want in this case.