java - Spring Boot super JAR : cannot be resolved to absolute file path because it does not reside in the file system

标签 java spring-boot

将 Spring Boot 版本 1.5.7.RELEASE 导出到可运行的 JAR 后,出现以下错误。由于安全原因,我不使用 maven,并且我在构建路径中添加了所有 JAR。

我在命令下运行

java -jar mailer.jar

然后我收到了你在屏幕截图中看到的错误

enter image description here

最佳答案

因为当打包的 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/

相关文章:

java - 如何读取Java中我们的系统(PC声卡或扬声器)正在播放的音频流

java - 子数组最大和

java - 使用jdbc代码将文件存储到MySQL

java - 如何使用 Spring Security 5 OAuth2 客户端和 RestTemplate 刷新 OAuth2 token

spring-boot - 属性引用异常 : No property findAll found for type

java - https://plugins.gradle.org/m2/发生了什么?

java - 变音符号的解码问题

spring-boot - 使用spring boot maven插件构建jar时如何在manifest.mf中添加Classpath属性

spring-boot - 为什么在为访问 token 交换授权代码时收到无效 token 响应? ( Spring 启动、oauth2、天蓝色)

spring-boot - 在 spring 中将 @PropertySource 限制为特定的 @Configuration 类