Maven打包時,如何包含資源文件(src/main/java | src/main/resources):
參考博客:http://blog.csdn.net/jsflzhong/article/details/52077075
在Maven項目中,一般將用到的資源文件(xml | properties | xsd等)放在src/main/resources下面,利用Maven打包時,Maven可以將這些資源文件打包到相應的jar或者時war中
1 可以在pom文件中進行配置:
**/*這樣的寫法,是為了保證各級子目錄下的資源文件都被打包
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/java</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </resource> </resources> </build>
2 可以使用build-helper-maven-plugin插件
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>add-resource</id> <phase>generate-resources</phase> <goals> <goal>add-resource</goal> </goals> <configuration> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build>
3 可以使用maven-resources-plugin插件
<build> <plugins> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>copy-xmls</id> <phase>process-sources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/classes</outputDirectory> <resources> <resource> <directory>${basedir}/src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build>