I got following error after export Spring Boot version 1.5.7.RELEASE to runnable JAR. I don't use maven because security reasons, and I added all JARs in build path.
I run below command
java -jar mailer.jar
then I received error as you see in screenshot
Because when your resource does not exist in packaged uber-jar, has problem with classpath. Use solution like this
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();
}
It seems like the application is trying to access a file through the AbstractFileResolvingResource.getFile() (a couple of rows down in the stack trace) which is not possible from a runnable spring boot jar (it may work when running from an IDE).
Try using getInputStream() instead, see for example this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With