Reputation: 3313
A library I need to use reads system property in the following way:
System.getProperty("library.system.property")
Is there any way to pass such a property to spring boot while starting the app or do I need to set it in the system?
Upvotes: 11
Views: 22522
Reputation: 5850
Update 2020-01-08
For spring-boot 2.2.2.RELEASE while develop
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dmy_system_properties=test1"
For spring-boot 1.5.x.RELEASE or below while develop
mvn spring-boot:run -Drun.jvmArguments="-Dmy_system_properties=test1"
For run as jar
java -Dmy_system_properties=test1 -jar service.jar
You can try with a runnable example, here https://www.surasint.com/spring-boot-pass-system-properties-in-command-line/
Upvotes: 10
Reputation: 409
you can also do it like this:
public static void main(String[] args) {
System.setProperty("key", "value");
SpringApplication.run(MyApplication.class);
}
Upvotes: 6
Reputation: 71
If you are using spring-boot maven plugin to execute the application, try (no line breaks)
mvn spring-boot:run -Drun.jvmArguments="-Xms2048m -Xmx4000m -XX:MaxPermSize=2048m
-Dlibrary.system.property=value"
Refer maven plugin for additional details
Upvotes: 2
Reputation: 415
You can pass it on the command line:
java -Dlibrary.system.property=value -jar myapp.jar
Upvotes: 12