Setting the HTTP Port for Java Applications
Last updated April 09, 2020
Heroku expects a web application to bind its HTTP server to the port defined by the
$PORT environment variable. Many frameworks default to port 8080, but can be configured to use an environment variable instead. In most cases, the port can be configured by adding a parameter to the
java command in an application’s
Procfile, but some frameworks provide a configuration file. The most common Java frameworks are listed here.
Spring-Boot provides a few different mechanisms for setting the HTTP port. It can be passed an option to the executable JAR file (i.e. the options after the
-jar app.jar options in your
Or as a Java system property:
In both cases, these options can be added to the
java command in an app’s
Procfile. Another option is a configuration element in the
For more info see Spring Boot documentation on Properties and Configuration
Webapp Runner (Tomcat)
Webapp Runner allows you to launch an exploded or compressed war on your filesystem into a Tomcat container with a simple
java -jar command. It accepts the following option to the executable JAR file (i.e. the options after the
-jar webapp-runner.jar options in your
When using the
heroku war:deploy and Heroku Maven Plugin tools, this option is configured for you. For more information, see the Webapp Runner documentation.
For more info see the Play documentation for Heroku.
The Dropwizard framework accepts a Java system property:
For more information see the Dropwizard Configuration reference.
The Thorntail framework accepts a system property:
For more information see the WildFly Swarm documentation.
The Grails 3 framework produces a WAR file that can be run with either Tomcat or Jetty. See the Webapp Runner section for more information.
For more information see the WildFly Swarm