java - 无法在 jar 文件(docker build)中加载资源文件。本地工作正常
问题描述
我在 jar 中有一个带有路径的证书文件-BOOT-INF/classes/keystore.jks
。我已经使用classpath:keystore.jks
Resource 来访问该文件。在本地,我能够获取该文件并能够运行 Spring Boot 应用程序。但是当我构建它并创建一个 jar 时,我可以看到该文件,但我遇到了异常 -
FileNotFoundException: file:/libs/app.jar!/BOOT-INF/classes!/keystore.jks (No such file or directory)\n\tat j.io.FileInputStream.open0(FileInputStream.java)\n\tat j.io.FileInputStream.open(FileInputStream.java:219)\n\tat j.io.FileInputStream.<init>(FileInputStream.java:157)\n\tat c.s.i.o.c.f.HttpConnectionFactoryImpl.loadKeystore(HttpConnectionFactoryImpl.java:119)\n\t... 55 common frames omitted\nWrapped by: c.s.i.o.c.e.SSLContextException: Unable to load keystore / truststore /file:/libs/app.jar!/BOOT-INF/classes!/keystore.jks
我尝试了以下不起作用的东西 -
storePath = ((ClassPathResource)ebbsTrustStore).getPath()
path = CheckKeytsotrePath.getInternalResource(storePath).getPath()
ResourceUtils.getFile("classpath:keystore.jks").getPath()
((ClassPathResource)ebbsTrustStore).getURL().toString()
我需要将此路径传递给库方法,该方法是BOOT-INF/lib
同一个 jar 中的一部分。如果您对此有任何解决方案/提示,请告诉我。
解决方案
推荐阅读
- python - 如何更改图例标记的颜色?
- powerbi - Power BI - 具有继承值的新行
- c# - 尝试激活控制器时无法解析类型“Microsoft.Graph.GraphServiceClient”的服务
- html - div 在 CSS 悬停时向上滑动
- c++ - CMake + VSCode:configure_file 和 linting
- python-3.x - 从同一目录运行多个 Colab Notebook
- scala - Scala 期货 - java.util.concurrent.RejectedExecutionException
- python - 在 python 中为 Binance 创建 Freqtrade 策略时,如何获取刚刚结束的蜡烛的信息?
- xamarin.forms - 自定义引脚(注释)xamarin 形式 ios 在 14 以下版本上未更改
- javascript - BleManager 反应原生