SpringBoot:SpringWeb项目+Vue项目dist包整合成jar包
接到需求做一个小功能项目,其中还要配备前端页面,并且将前端打包进后端jar包内,由jar包运行。
项目结构
将Vue打包之后的dist文件放到resouces资源路径下
修改pom文件
将下面的build配置替换掉pom中的build
<build>
<finalName>自定义项目jar名称(可以用 ${project.artifatId})</finalName>
<resources>
<resource>
<!-- 加载resources下的dist文件夹 -->
<directory>src/main/resources/dist</directory>
<targetPath>META-INF/resources/</targetPath>
</resource>
<resource>
<!-- 加载resources下的dist文件夹 -->
<directory>src/main/resources</directory>
<includes>
<include>sql/**</include>
<include>*.yml</include>
<include>logback.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
之后通过maven打包就可以将dist文件加载到jar内了,访问jar端口就可以看到页面
-----------------------------------
作者:怒吼的萝卜
链接:http://www.cnblogs.com/nhdlb/
-----------------------------------