springboot打成jar后获取resources下文件失败, cannot be resolved to absolute file path because it does not resid
读取resources下的文件quotaShow.jasper
本地开发环境能正常下载:
ClassPathResource resource = new ClassPathResource("jasper" + File.separator + "quotaShow.jasper");
reportFile = resource.getFile();
打jar包发布至linux服务器时报错:
class path resource [xxxx] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:xxxx.jar!/BOOT-INF/classes!xxxx
解决方法:
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("jasper"+File.separator+"quotaShow.jasper");
Resource resource = resources[0];
InputStream is = resource.getInputStream();
String filePath= this.getClass().getClassLoader().getResource("jasper"+File.separator+"quotaShow.jasper").getFile();
File reportFile = new File(filePath);FileUtils.copyInputStreamToFile(is,reportFile);
拿到file后,后面走正常的下载流程。
springboot打成jar后获取resources下文件失败, cannot be resolved to absolute file path because it does not resid相关推荐
- springboot打成jar后获取classpath下的文件
直接上代码 JAR包用这个 //获取容器资源解析器ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( ...
- Spring Boot打包成执行jar后获取classpath下文件异常解决
Spring boot 打包后 jar文件,IDEA调试时候没什么问题,可是打包成执行jar后发现有异常抛出: class path resource [1.jpg] cannot be resolv ...
- springboot-项目获取resources下文件的方法
spring项目获取resources下文件的方法 最近写读取模板文件做一些后续的处理,将文件放在了项目的resources 下,发现了一个好用的读取方法: 比如上边是你需要读取的文件: 读取的方法如 ...
- springboot打成Jar包下载Excel模板文件损坏问题
最近遇到Springboot环境项目打成jar后下载Excle文件出现损坏问题,我是在网上找了这种方法解决的: String fileName = "aaa.xlsx"; Clas ...
- springboot忽略证书_SpringBoot获取resource下证书失败
1.第一种失败的情况: 本来使用Spring的上下文容器获取文件,将证书文件放在resource下,编译后获取文件会出现报错 java.security.spec.InvalidKeySpecExce ...
- springboot打包后读取resources下文件
pom.xml 配置 <build><resources><resource><directory>src/main/resources</dir ...
- ueditor百度富文本编辑器linux下报错: class path resource [config.json] cannot be resolved to absolute file path
https://www.cnblogs.com/findtasy/p/10043273.html
- SpringBoot项目打包成jar后读取包内文件报错问题解决方法
文章目录 问题描述 解决办法 问题描述 Springboot项目在开发环境中,使用 ResourceUtils.getFile("classpath:files/test.xlsx" ...
- Java程序启动同时复制resources下文件到jar包同级目录
Java代码调用.exe,包括获取exec()中的日志并打印,可以看我之前的博客 一.Java调用exe打包成jar的调用方式有俩种: Java程序中resources下的exe等文件,是可以同时打包 ...
最新文章
- mysql -- 预处理语句
- PAT1017 和强迫症做斗争
- linux ldconfig 与 /etc/ld.so.conf 动态函数库配置
- Riding the Fences USACO 3.3 欧拉路径(dfs+floodfill)
- nodeJs实现文件上传,下载,删除
- 一文整理Docker【Docker使用(更新中)】
- C语言学习之有一个已排好序的数组,要求输入一个数后,按原来排序的规律将它插入数组中
- Windows Phone开发(16):样式和控件模板 转:http://blog.csdn.net/tcjiaan/article/details/7367260...
- C语言实现2048游戏(Windows版)
- sonar扫描android项目配置 mac版
- JavaScript获取地址栏中的链接参数
- 饥荒联机版服务器重置,饥荒联机版服务器重置世界 | 手游网游页游攻略大全
- 叶脊网络架构(Spine-Leaf)
- QQ安全检查未通过,禁止下载该文件
- 什么是RS485总线?
- Window XP驱动开发(二) 环境搭建(VS2008+WDK+DDKWzard)及示例源码分析
- yara规则--编写
- JS学习108-161
- 新能源与自动驾驶汽车市场
- Java物联网新零售项目 立可得-day01
热门文章
- 什么是类、什么是对象
- C语言字符串处理函数 strchr()和 strstr()的区别及使用
- 科技不总是冷冰冰,智能便携打印机让文字更有温度!——硬件方案篇
- 【正点原子FPGA连载】 第十七章 RS485串口通信实验 -摘自【正点原子】领航者ZYNQ之FPGA开发指南_V2.0
- Mysql tinyint(1)与tinyint(4)的区别
- MobPush创建推送
- 逆波兰式(后缀式)详解
- 3Dmax制作立体的文字教程
- matlab二阶锥,二次规划和锥规划
- MATLAB Simulink
- MathWorks 中国
- 织梦网站搬家流程揭秘