Skip to content
July 8, 2010 / edeustace

Processing resources with the Maven war plugin

The problem:
You have some files in your maven web application folder that you’d like to process and then add them to the generated .war. However the maven war plugin doesn’t have a phase that will let you execute such processing before the war is built.

The solution:
Configure an additional folder as a ‘webResource’ in the war plugin configuration, that you will send your processed files to.

1. In a earlier build phase (eg: process-resources) copy the source file that you want to process to predefined folder (eg: target/preassembly).
2. Process the file however you like
3. When the war plugin begins, because you have specified the folder where the processed file is as a webResource, it will take that file and copy it into the war, overwriting the file that was originally copied over from src/main/resources.

So say we have a simple war project that has a properties file:
And this properties file contains a token: “${tokenToReplace}” that you want to replace.

To modify something within this file and have it added to your .war, the following pom.xml will do the job:

				<!-- copy resources from this folder into the webapp before packaging -->
			<!-- do some processing on your resources files -->
				<echo message="processing files..."/>
				<!-- copy the file to be processed -->
				<!-- do the processing (replace the token value with a value passed in on the command line) -->
					token="${tokenToReplace}" value="${}"/>

You can add a value here from the command line if you want:
mvn install”I’m the new value”

The line above will add “I’m the new value” as the value for the ‘value’ key in

Credit to:



Leave a Comment
  1. hjohn06 / Dec 8 2010 8:57 pm

    Nice post. I was looking for something like this. I was one step away before reading your post. Well I was exploding the war and then trying to keep the plugin from copying the files overwriting my changes during packaging, but this is easier. This is a lot simpler. But I believe you could have just used filters on the war plugin, since you are using maven style variables (the ${variable} thing). I was looking to replace values without using ${variable}. I need a default value in place prior to maven running.

  2. edeustace / Dec 12 2010 2:38 am

    Thanks for the tip, I’ll check it out. I wonder about the filtering file structure. Is that set in stone? The docs don’t really explain why its in that structure. So I wonder can one pass in variables from the command line?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: