javaspringspring-mvcjarserver-configuration

Configure server port when running jar


I currently working on an Spring Boot application written in Java 8 using Gradle. What I am looking for is to pass as an argument the server port when running the Jar from the command line.

For example:

Can anyone help me with this ?


Solution

  • From Spring boot documentation, the command line is :

    java -Dserver.port=8888 -jar myApplication.jar
    

    You can also use Spring boot configuration file as described in the documentation.