将 Spring Boot 版本 1.5.7.RELEASE 导出到可运行的 JAR 后,出现以下错误。由于安全原因,我不使用 maven,并且我在构建路径中添加了所有 JAR。
我在命令下运行
java -jar mailer.jar
然后我收到了你在屏幕截图中看到的错误
最佳答案
因为当打包的 uber-jar 中不存在您的资源时,类路径有问题。使用这样的解决方案
String fuu = "";
ClassPathResource classPathResource = new ClassPathResource("static/foo.txt");
try {
byte[] binaryData = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());
fuu = new String(binaryData, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
关于java - Spring Boot super JAR : cannot be resolved to absolute file path because it does not reside in the file system,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53184517/