Sorry I'm so late to the party, but conferences have a tendency to get in the way. The way to think about this is that staging only happens once, in a different environment, than your application will run in. So if you run multiple instances of your application, the values for
$VCAP_APP_PORT,
$PORT, and
$VCAP_APP_HOST will vary between each instance. Because they vary (3 instances will have 3 different
$PORT values) there is no correct value to write out at staging time. As Tao and Daniel mention there are a number of ways to pass those values into an application, but the preferred way is to reference the environment variable directly. The Java Buildpack does this typically by setting a container-specifc
system property or
environment variable that references
$PORT. While it's not universal, most frameworks allow configuration via environment variable; in fact Java is one of the most environment variable-hostile ecosystems out there, and I don't believe that we've yet found a framework that doesn't allow this.