Maven项目的标准目录结构
src
main
java 源文件
resources 资源文件
filters 资源过滤文件
config 配置文件
scripts 脚本文件
webapp web应用文件
test
java 测试源文件
resources 测试资源文件
filters 测试资源过滤文件
it 集成测试
assembly assembly descriptors
site Site
target
generated-sources
classes
generated-test-sources
test-classes
xxx.jar
pom.xml
LICENSE.txt
NOTICE.txt
README.txt
资源文件的配置
配置文件通常与.java文件一起放在src/main/java目录
有时候有些配置文件通常与.java文件一起放在src/main/java目录
有的时候还希望把其他目录中的资源也复制到classes目录中。
这些情况下就需要在Pom.xml文件中修改配置了,可以有两种方法:
一是在<build>元素下添加<resources>进行配置。
另一种是在<build>的<plugins>子元素中配置maven-resources-plugin等处理资源文件的插件。
<build>元素下添加<resources>进行配置
<build> <resources> <!-- 指定了java和resources下的xml文件,xlsx文件,xls文件打包到根目录 --> <resource> <directory>src/main/java</directory> <includes> <include>*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.yml</include> <include>**/*.properties</include> <include>**/*.xml</include> <include>*.xlsx</include> <include>*.xls</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> <plugins> <!--解决打包没有mainClass问题--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.6.RELEASE</version> <configuration> <fork>true</fork> <mainClass>com.power.app.AppWebApplication</mainClass> <includeSystemScope>true</includeSystemScope> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> <finalName>app-web</finalName> </build>
<build>的<plugins>子元素中配置maven-resources-plugin
<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>
来源 https://www.cnblogs.com/dreamroute/p/6729147.html