OmriYaHoo OmriYaHoo - 10 months ago 74
Java Question

Spring Boot Jar Execution internal properties files

I have a Spring Boot application that runs properly when I run it from Intellij as maven configurations.

I have a project structure of environments that is defined with properties files.



Our framework works in a way that we are choosing the env with VM arguments.
for example

After packaging the App to an executable JAR and trying to run it, Spring Boot can't identify the properties files under
path of the project.

When I look inside the JAR the properties files are under

The error is: conf\ (The system cannot find the path specified)

2017-07-11 10:52:52.864 INFO 17896 --- [main] n.lifecycle: Can't find configuration file [conf\]
2017-07-11 10:52:52.865 ERROR 17896 --- [main] n.lifecycle: configuration file [null] not found (use default properties as error handling)

I've tried to work with the documentaion here:
but nothing seems to fix it.
Also tried to work with this guide - but also failed...

The guides are referring to the properties files as "external" but my properties are packed in the JAR.

Answer Source

I've found out what's wrong. Our in-house framework that's loading the resources are using File.separator to read the path of the resources.

Now for some reason when the jar is created with maven spring boot plugin the classpath is built with '/' for example /C:/Users/MyUser/Projects/MyApp/target/MyApp-1.0.1.jar!/BOOT-INF/classes!/ (the resources are in classes path inside of the jar of course)

And when we are trying to run the jar it's trying to read the resources with '\' so the path that is built is (if we choose "dev" for example) /C:/Users/MyUser/Projects/MyApp/target/MyApp-1.0.1.jar!/BOOT-INF/classes!/conf\dev and that is why the app is failing to load.

I still don't know why this is happening.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download