Configure server port when running jar

T code picture T code · Jan 17, 2017 · Viewed 46.3k times · Source

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:

  • java -jar myApplication.jar --port=8888: This runs my Spring boot application using port 8888
  • java -jar myApplication.jar: Since no port number is passed as argument, the spring boot application should run on a default port number (let's say 8080)

Can anyone help me with this ?

Answer

Mickael picture Mickael · Jan 17, 2017

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.