How to copy files to target build directory in maven?

This is a short tutorial on how to copy property files from an input directory to the target build directory in maven.

Maven creates the [standard directory structure] (/2011/12/maven-project-structure.html) for an application. You can check my other posts on maven commands

Default resources files are located in the `src/main/resources folder. which will be copied to target/classes during build and WEB-INF/classes in war file generation

When you are packaging the project, these properties are automatically copied to the target folder.

Sometimes you have a folder called src/conf which contains configuration properties. src/conffolder is not part of the maven standard folder structure.

How do you copy the files to the target folder during the package?

maven provides a maven-resources-plugin plugin that copies files from source to target folders.

The below code copies files from src/conf folder to target/classes/conf folder.

You have to use regular expressions with the includes value as **/.


How to make Maven copy resource files into WEB-INF/lib directory?

Suppose you want to copy configuration files to the web-inf/lib of a war file. Then how can you copy the files?

You have to use the maven-war-plugin plugin in pom.xml

The below code copies files from src/conf to target/WEB-INF/lib folder as well as war file/WEB-INF/lib folder.

Under webResources, give input directory using the directory tag and provide includes the files to add. Configure Output path using targetPath tag.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.