Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: passing system properties to maven

I tried:

mvn -Dspring.profiles.active=dev spring-boot:run

but it does not affect my default configuration. I've googled a little and found:

mvn -DargLine="-Dspring.profiles.active=dev" spring-boot:run

but if fails as well.

When I run:

mvn package

and then:

java -Dspring.profiles.active=test -jar target/app-1.0.0.jar

it works as expected (the profile is changed) but fails to find file from resource dir (FileNotFound exception) which is loaded this way:

new File(getClass().getClassLoader().getResource("data.yml").getFile())

There is no problem with this file when maven is used to run the app.

Any suggestions?

like image 784
biera Avatar asked Jan 20 '15 15:01

biera


Video Answer


1 Answers

With the current version (>= 2.0.0.RELEASE), the parameter is -Dspring-boot.run.jvmArguments

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev"

Source: Running your Application with Maven

To activate a speciffic profile, there is a shortcut available:

mvn spring-boot:run -Dspring-boot.run.profiles=dev

Source: Specify Active Profiles

like image 164
Benoit Avatar answered Sep 28 '22 22:09

Benoit