spingboot项目打包将静态资源分离出来
时间: 2023-08-03 15:03:38 浏览: 69
可以使用Spring Boot的插件进行静态资源的分离,具体步骤如下:
1. 在pom.xml中添加以下插件:
```
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.10.0</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v14.15.4</nodeVersion>
<npmVersion>6.14.10</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
2. 在src/main/resources/static文件夹下放置静态资源。
3. 运行mvn clean install命令打包项目,此时会自动执行插件,将静态资源分离出来。
4. 在target/classes/static文件夹下可以找到分离出来的静态资源。
阅读全文