spring boot打包文件后,报错\No such file or directory
现象:
一段代码:
ClassLoader loader = XXXUtil.class.getClassLoader();
String jsFileName = loader.getResource("") + "/resources/" + fileName;
logger.info("文件路径为"+jsFileName);
在本地开发测试,完全ok(windows下);
上测试环境,报错/opt/jar_code/xxx/xxxx.jar!/BOOT-INF/classes!/resources/xxxxx.js (No such file or directory)
上述目录出现"!" 比较奇怪。
解决方案:
不读文件路径,直接读文件流
input = XXXUtil.class.getClassLoader()
.getResourceAsStream("resources" + File.separator + fileName);
reader = new InputStreamReader(input, Constant.UTF_8);
初看两种方式,应该是一致的。
其实则不同:
1.使用文件路径,要求该路径下的文件在文件系统上是可以访问的。因为jar文件需要解压才能访问,直接访问不了。
2.使用流,直接读文件,则不存在上述要求。
spring boot打包文件后,报错\No such file or directory的更多相关文章
- spring boot启动STS 运行报错 java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext
spring boot启动STS 运行报错 java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext 学习了: http ...
- 安装Yellowfin报错——No such file or directory: '/tmp/pip-build-jykvuD/YellowFin/README.md'
https://blog.csdn.net/quqiaoluo5620/article/details/80608474 在Pycharm中安装Yellowfin时一直报错"no such ...
- spring boot 打包war后 部署到外部 tomcat 的具体正确操作【包括修改端口 与 去除请求路径的工程名】
1.前言 工程做好了,总不能放在idea运行吧?不然怎么把项目放到云服务器呢?[这一篇随笔不讲解发布的云服务器的操作,在其他随笔有详细记载.] 解决的方案是把springboot 工程 打包成war文 ...
- spring boot 打包jar后访问classes文件夹的文件提示地址不存在
报错内容:class path resource [client.p12] cannot be resolved to absolute file path because it does not r ...
- spring boot jar包替换报错之Unable to open nested entry 'BOOT-INF/lib/cache-api-0.4.jar'.
spring boot用layout ZIP打出来的包能够支持外部classpath,但是当用rar/7zip替换其中的jar后,报下列错误: Unable to open nested entry ...
- Spring Boot JPA分页 PageRequest报错
在使用Spring Boot JPA分页 PageRequest分页时,出现如下错误: 本来以为是包导入出现了问题,结果发现并不是.导入包如下: 后来在网上查找相关资料,发现这样的用法,好像也可以用, ...
- spring boot jpa 使用update 报错解决办法
在spring boot jpa 中自定义sql,执行update操作报错解决办法: 在@Query(...)上添加 @Modifying@Transactional注解
- 使用Spring boot整合Hive,在启动Spring boot项目时,报错
使用Spring boot整合Hive,在启动Spring boot项目时,报出异常: java.lang.NoSuchMethodError: org.eclipse.jetty.servlet.S ...
- 【spring cloud】【spring boot】项目启动报错:Cannot determine embedded database driver class for database type NONE
解决参考文章:https://blog.csdn.net/hengyunabc/article/details/78762097 spring boot启动报错如下: Error starting A ...
随机推荐
- LightOJ 1348 Aladdin and the Return Journey
Aladdin and the Return Journey Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged ...
- CodeForces 362C
分析:首先我们要知道调用swap()函数的次数跟什么有关.可以观察发现在Insertion Sort里,当且仅当a[j](j∈[0,i)) > a[i]时会调用一次swap(),也就是说有多少个 ...
- cogs——1298. 通讯问题
1298. 通讯问题 ★★ 输入文件:jdltt.in 输出文件:jdltt.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员,每个队员 ...
- tomcat服务器配置把Http协议强制转化为Https
1)在命令提示符窗口,进入Tomcat目录,执行以下命令: keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass ...
- MySQL大小写问题的简单说明(关键字/函数/表名)(转)
MySQL语句中字母大小写规则随着语句元素的不同而变化,同时还要取决于MySQL服务器主机上的操作系统. SQL关键字与函数名 关键字和函数名不区分字母的大小写.如.abs.bin.now.versi ...
- fastjson将java list转为json字符串
1.直接用fastjson的静态方法string JSON.toJSONString(list)方法就行,JSON.toJSONString(list)将java list转为json字符串. 2.t ...
- firebug 扩展介绍和下载
https://getfirebug.com/wiki/index.php/Firebug_Extensions#Firecookie https://addons.mozilla.org/zh-CN ...
- 内核信号处理 & CPU8个通用寄存器
内核信号处理参考: http://www.spongeliu.com/165.html 信号本质上是在软件层次上对中断机制的一种模拟(注意区分中断.异常.信号),其主要有以下几种来源: 程序错误:除零 ...
- 1.5 - 动态路由协议ISIS
IS-IS 特征: 1:协议操作起来,比OSPF要简单 2:扩展性比OSPF要好,易于扩展 3:对IPv6有很好的支持 4:能够同时支持IP网络,和CLNS网络(OSI网络)(集成的IS-IS) 5: ...
- [Vue-rx] Stream an API using RxJS into a Vue.js Template
You can map remote data directly into your Vue.js templates using RxJS. This lesson uses axios (and ...