I have a Spring Boot application which is to be deployed as a .war
on Cloud Foundry. It has many properties files which are kept in src/main/resources/
folder. The application uses custom libraries as dependencies which reads these properties.
For example: one of the dependencies is a custom logger library and it reads the log.properties
file at runtime. Now most of these libraries use the ClassLoader.getSystemresource().getFile()
function to read the properties. Since it is a dependency, I can't edit the libraries.
Everything works locally while testing via STS. But when the .war
file is generated and deployed, it is unable to find any of these resource files and hence fails. All the property files are present in the .war
and if I use Spring's ClassPathResource()
methods to access the files, it is accessible.
I have seen similar questions on Stack Overflow which advise to read files as streams instead of file and other similar solutions but none of this will work in my case since I will not be able to modify the dependency source code. Is there any way to achieve this?
My problem is very similar to this question Classpath resource not found when running as jar except that I wont be able to apply the solution given.
Edit
As requested below is the code snippet
File logfile = ClassLoader.getSystemResource("log.properties").getFile();
This does not work. Where as
File logFile = new ClassPathResource("log.properties").getFile();. works. But i need the first code snippet to work since it is inside a jar and i can't modify it.