Maybe mvn clean package
is one of the easiest operation in java programing. Howerver, I recently encountered a problem of packaging, which took up some of my time.
This was the initial package config in maven pom:
1 2 3 4 5 6 |
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> |
And this is the path of the file I wanted to package and read:
1 |
src/main/resources/template/xxx.xml |
Executing the package command (mvn clean package
) and opening the jar with compression software (e.g. WinRAR), the file was expected to locate at BOOT-INFO/class/template
. However I could not find it. Though all files in resources folder directly existed, the others in subdirectories was not there.
Helped by Google, I found the key. If we want to package all files in resources folder including files in subdirectories, we need to add these three lines to maven package config:
1 2 3 |
<includes> <include>**/*</include> </includes> |
The full config is :
1 2 3 4 5 6 7 8 9 |
<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*</include> </includes> </resource> </resources> |
Oh, forget it: the config is in the <build>
tag in maven pom.xml file.
End!