Gibi Gibi - 5 months ago 73
Java Question outside jar file how to

As stated in spring-boot-reference:

On your application classpath (e.g. inside your jar) you can have an that provides a sensible default property value
for name. When running in a new environment, an
can be provided outside of your jar that overrides the name

I place a duplicated with overridden name on the same path as jar file, however when running the application with:

java -jar target/myproject-0.0.1-SNAPSHOT.jar

The name value is not overridden, it still refers to the one inside inside jar file. I also tried:

java -Dspring.config.location=/target/ -jar target/myproject-0.0.1-SNAPSHOT.jar

But it does not work, please help.


When I change the current directory to
and run it, it works.

java -jar myproject-0.0.1-SNAPSHOT.jar

Why? Why cannot be outside the path and run it?


Just as you say in your edit, it doesn't work because we you trying to launch the jar from another folder.

The reason it doesn't work, is that spring boot looks for files/folder relative your current folder.

You can:

(1) copy one level below target (in ./ or ./config/)

(2) Or execute like this (without forward slash for the location path):

$ java -Dspring.config.location=target/ -jar target/myproject-0.0.1-SNAPSHOT.jar