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 ...
随机推荐
- BZOJ 4976 [Lydsy1708月赛]宝石镶嵌
[题解] 我们设总共有m个二进制位出现过1,那么如果n-k≥m,显然所有的1都可以出现,那么答案就是把所有的数或起来. 如果n-k<m,那么因为k不超过100,ai不超过1e5,所以n不超过11 ...
- 【Codeforces 567D】One-Dimensional Battle Ships
[链接] 我是链接,点我呀:) [题意] 长度为n的一个序列,其中有一些部分可能是空的,一些部分是长度为a的物品的一部分 (总共有k个长度为a的物品,一个放在位置i长度为a的物品会占据i,i+1,.. ...
- mysql执行show processlist unauthenticated user 解决方法
一台unibilling机器前几天突然负载变重. 在top中发现cpu被大量占用. agi程序运行的很慢,并出现僵尸进程. 其实当时只有50个左右的并发呼叫. 远远达不到正常水准. 重新启动机器问题也 ...
- java并发操作
项目中常用的java并发操作 一.java8新特性java并发流操作(结合纳姆达表达式) List<String> list = new ArrayList<>(); list ...
- docker: useful commands
docker build -t stock_data_repo_instance24 . docker run -v /opt/log:/opt/log -d -it stock_data_repo_ ...
- Redis是单线程的
Redis是单线程的 学习了: http://blog.csdn.net/liupeng_qwert/article/details/77263187 https://www.cnblogs.com/ ...
- 1. MaxCounters 计数器 Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
package com.code; import java.util.Arrays; public class Test04_4 { public static int[] solution(int ...
- 1. 数组小挪移CyclicRotation Rotate an array to the right by a given number of steps.
数组小挪移: package com.code; import java.util.Arrays; public class Test02_2 { public int[] solution(int[ ...
- Android SwipeToDismiss:左滑/右滑删除ListView条目Item
<Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(githu ...
- C++学习之多重继承与虚继承
一.多重继承 我们知道,在单继承中,派生类的对象中包含了基类部分 和 派生类自定义部分.同样的,在多重继承(multiple inheritance)关系中,派生类的对象包含了每个基类的子对象和自定义 ...