因为最近想弄一个自己的脚手架项目,顺带着想学一下先进的前端框架Vue.js,所以在springboot中整合了Vue.js。
我把Vue.js 的前端项目放在了resources/webapp目录下,当Vue.js build出结果到resources/statics下以后,这个webapp作为源码目录是不应该被打包到最后部署的jar包中的。
于是想把这个resource/webapp目录给屏蔽掉。
我在网上查询了一下,找到了一些方法。
https://blog.csdn/ya2dan/article/details/50786464
因为一直保持着最小改动的原则,这里的方法我也没有具体的测试,因为它不仅增加了一个打包插件,而且还对springboot自带的打包插件增加了设置。
这篇文章开头提到的这种基于resources标签的方法非常符合我心中的方式,经过尝试,终于用这种方式成功的排除掉了resources/webapp。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<excludes>
<exclude>webapp/**</exclude>
</excludes>
</resource>
</resources>
</build>
首先一个不一样的地方就是,增加了一个filtering节点并且设置值为true
然后在excludes中用/**匹配了webapp下面的所有内容
根据这种原则,我们在打包时只想包含指定的资源文件,可以用<includes>标签来实现。
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>webapp/**</include>
</includes>
</resource>
</resources>
如此,只有webapp下面的资源文件才能被打包到目标jar包中。
这种方式来排除资源,即简洁,又能够很容易就明白其中的原因。
更多推荐
spring boot maven打包时排除资源目录
发布评论