Blog

How to configure Server Port when running JAR?

Java

How to configure Server Port when running JAR?

To configure the server port when running a JAR file, you typically need to either modify the configuration within the application or pass the port number as a parameter when executing the JAR file.

Here’s how you can do it in a few different scenarios:

Modifying Application Configuration:
If your application reads configuration from a file (e.g., a properties file), you can modify the configuration to specify the server port there. Look for a configuration file within your JAR or alongside it, and modify the appropriate property.

Command-Line Parameter:
Some applications allow you to specify configuration parameters via command-line arguments. You can typically pass the server port number as a parameter when running the JAR file. The exact syntax depends on the application, but it might look something like this:

java -jar yourapp.jar --server.port=8080

Here, –server.port=8080 is an example of passing the port number as a command-line argument.

Environment Variable:
Some applications also support configuring settings via environment variables. You can set an environment variable specifying the port number before running the JAR file. Again, the exact variable name depends on the application, but it might be something like SERVER_PORT. Then, when you run the JAR file, it will pick up this environment variable.

System Property:
Java applications can also read configuration from system properties. You can pass system properties to the JVM when starting the application. For example:

java -Dserver.port=8080 -jar yourapp.jar
Spread the love

Leave your thought here

Your email address will not be published. Required fields are marked *