Classpath resource not found when running as jar
来源:互联网 发布:iframe 端口不同 跨域 编辑:程序博客网 时间:2024/06/02 00:01
File file = new ClassPathResource("countries.xml").getFile();File file= ResourceUtils.getFile("classpath:test.txt");
Resource resource = new ClassPathResource(templateFile);String file = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
/**
* {@link Resource} implementation for class path resources. Uses either a
* given {@link ClassLoader} or a given {@link Class} for loading resources.
*
* Supports resolution as {@code java.io.File} if the class path
* resource resides in the file system, but not for resources in a JAR.
* Always supports resolution as URL.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 28.12.2003
* @see ClassLoader#getResourceAsStream(String)
* @see Class#getResourceAsStream(String)
*/
public class ClassPathResource extends AbstractFileResolvingResource {
resource.getFile() expects the resource itself to be available on the file system, i.e. it can’t be nested inside a jar file. This is why it works when you run your application in STS but doesn’t work once you’ve built your application and run it from the executable jar. Rather than using getFile() to access the resource’s contents, I’d recommend using getInputStream() instead. That’ll allow you to read the resource’s content regardless of where it’s located.
https://stackoverflow.com/questions/25869428/classpath-resource-not-found-when-running-as-jar
https://stackoverflow.com/questions/36371748/spring-boot-access-static-resources-missing-scr-main-resources
- Classpath resource not found when running as jar
- TexMaker - “File not found” when viewing as pdf
- Jacob Not working when running as service on Windows 2008 (win7)
- 找不到文件异常java.io.IOException: Resource [classpath:shiro.ini] could not be found.
- Shrio | java.io.IOException: Resource [classpath:shiro.ini] could not be found
- ignore-resource-not-found
- eclipse导出jar时出现Class files on classpath not found or not accessible for ...
- 打包JAR错误 Class files on classpath not found or not accessible for 问题的解决
- When start tomcat, got the error: Resource /WEB-INF/classes not found
- Class not found when unmarshalling
- source not found when debugging
- Class not found when unmarshalling
- Class not found when unmarshalling
- file not found resource.cfg
- Jasper SubReport Resource Not Found
- Android resource not found问题
- .classpath 配置文件 class not found Exception
- Error running app: Default Activity Not Found
- [hongwgw笔记]2017年8月16日
- Cabac
- 20170816WindowsPrj01_01_文件扫描器
- libev学习资料
- 《深入理解Java虚拟机学习笔记之垃圾收集器与内存分配策略》
- Classpath resource not found when running as jar
- msm8916 camera driver添加新摄像头kernel hal修改
- linux系统中如何建立与删除软连接(方便快捷使用,大量节约时间)
- ssh允许root登录
- Js中String类型方法用法大全
- 机器视觉开源代码
- shell 双引号"" 单引号'' 反引号`` 的区别
- Oracle程序的优点和我缺点我是这样喜欢它的
- Java继承知识点总结(加面试题实例)