4

I have a springboot project with default structure. I have an excel file under resources/data. My program need to load excel file and dump data into different tables from each sheet.

When I run from Eclipse, program loads excel file correctly and everything looks good. However, when I deploy the same App on Docker, it fails to read the File from resources.

Have anyone encountered this issues? How have you solved it?

1
  • 3
    When we run an application from a Jar then, the way we read file needs to be changed. Please check stackoverflow.com/questions/3369794/… Commented Jun 26, 2018 at 4:45

1 Answer 1

6

First of all try to check whether the Docker is a reason, or there is an issue with java code. Spring boot creates an artifact that can be run with just java -jar <your-spring-boot-artifact.jar>

If this doesn't run even without docker, then you should change the way you access Excel files from spring boot application (your java code): if the file is in resources folder, it should be packaged into the spring boot artifact.

In this case, you have to use getClass().getResourceAsStream() to access the file, and not rely on java.io.File API, because File API doesn't allow working with files inside a Jar, its not a regular filesystem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, getResourceAsStream() worked as opposed to getFile, cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.