问题
打包出来的jar包里面没有html,js,css文件
解决方案
在pom.xml文件下的build选项中的src/main/resources的目录下 添加配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.css</include>
<include>**/*.js</include>
<include>**/*.html</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
src/main/resources/ true **/*.properties **/*.xml **/*.txt **/*.sql ```
读取resource下的文件(edu)
方式1:
InputStream inputStream = this.getClass().getResourceAsStream(“/localfile/” + localFileName);
方式2:
>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.1</version>
</dependency>
String path = file1.getAbsolutePath();
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>@[*]</delimiter>
<delimiter>$[*]</delimiter>
</delimiters>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.txt</include>
<include>**/*.sql</include>
<include>**/*.xlsx</include>
<include>**/*.xls</include>
</includes>
</resource>
</resources>
</build>
import cn.hutool.core.io.FileUtil;
String filePath = "localfile" + File.separator + localFileName;
File file1 = FileUtil.file(filePath);
- 个人网站:http://www.jiangjiesheng.cn
- 微信技术交流:yanfahezuo