maven中默认只能读取resources文件夹下的资源,如果要读取其他路径下的资源文件,那么就需要用到maven-resources-plugin这一插件
(1)在maven配置文件pom.xml中导入插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
(2)在build节点下面添加resource配置:
<resource>
<!--从此目录下读取全部以.properties和.xml开头的文件-->
<directory>src/main/resources/</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<!--从此目录下读取全部以.properties和.xml开头的文件-->
<directory>src/main/java/</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>