I have two Play framework web applications running on my system on ports 9001 and 9002. I was wondering if there was any way I could retrieve which port they were running on from within my Java code.
Is this possible?
I have two Play framework web applications running on my system on ports 9001 and 9002. I was wondering if there was any way I could retrieve which port they were running on from within my Java code.
Is this possible?
Yes. You can get the port like this:
int port = Integer.parseInt(Play.configuration.getProperty("http.port", 9000));
Of course, you have to import the class play.Play.
In Play 2.4.x:
Play.application().configuration().getString("http.port");
or simply:
System.getProperty("http.port");
This only works in production mode, when the http.port is set via the Java -D parameter.
Since the system does not let me comment yet, I'm forced to add my comment here.
The given answer by Carsten must be for play1, for play2 see Retrieving port number in Play Framework 2 app