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 ...
随机推荐
- 洛谷 4251 [SCOI2015]小凸玩矩阵
[题解] 二分答案+二分图匹配. 先二分最小值Min,然后扫一遍这个矩阵,把满足a[i][j]<=Min的i,j连边,之后跑二分图匹配,如果最大匹配数大于等于n-k+1,当前的Min即是合法的. ...
- 【01】CSS3 Gradient 分为 linear-gradient(线性渐变)和 radial-gradient(径 向渐变)(转)
CSS3 Gradient 分为 linear-gradient(线性渐变)和 radial-gradient(径 向渐变).而我们今天主要是针对线性渐变来剖析其具体的用法.为了更好的应用 CSS3 ...
- String与StringBuffer,StringBuilder
在java中有3个类来负责字符的操作. 1.Character 是进行单个字符操作的, 2.String 对一串字符进行操作.不可变类. 3.StringBuffer 也是对一串字符进行操作,但是可变 ...
- SQL 快速参考-----http://www.runoob.com/sql/sql-quickref.html
http://www.runoob.com/sql/sql-quickref.html SQL 快速参考
- 【MangoDB分片】配置mongodb分片群集(sharding cluster)
配置mongodb分片群集(sharding cluster) Sharding cluster介绍 这是一种可以水平扩展的模式,在数据量很大时特给力,实际大规模应用一般会采用这种架构去构建monod ...
- codevs1099 字串变换
题目描述 Description 已知有两个字串 A$, B$ 及一组字串变换的规则(至多6个规则): A1$ -> B1$ A2$ -> B2$ 规则的含义为:在 A$中的子串 A1$ ...
- Java虚拟机深入JVM内核—原理、诊断与优化视频教程
http://www.eimhe.com/forum.php?mod=viewthread&tid=142832&highlight=%C4%DA%BA%CB
- Vim tips——Working with external commands
A common sequence of events when editing files is to make a change and then need to test by executin ...
- Ubuntu上面安装Redis Python
Ubuntu上面安装Redis Python 1,下载redis源码https://redis.io/download,下载地址:http://124.205.69.169/files/A092000 ...
- SharpDevelop 如何切换设计视图和代码视图
仅在MainForm.cs跟MainForm.Designer.cs文件页面上,底部有可以切换源代码跟设计的按钮(别的地方都木有) 点击就切换过来了