sandris sandris - 2 months ago 59
Java Question

Get command-line arguments from spring-boot:run

Is there any way to input arguments when launching spring-boot application (mvn spring-bbot:run) from commandline and then get them in main()?


Looking at the source code of the spring-boot-maven-plugin I found that you need to do:

mvn spring-boot:run -Drun.arguments="arg1,arg2"

If you are using Gradle and you want to be able to pass command line arguments to the Gradle bootRun task, you first need to configure, for example like so:

bootRun {
    if ( project.hasProperty('args') ) {
        args project.args.split('\\s+')

and run the task using gradle bootRun -Pargs="arg1 arg2"