Getting the port number in the application using the Play Framework

I have two web applications for the Play platform running on my system, on ports 9001 and 9002. I was wondering if it was possible to somehow restore the port where they started from my Java code.

Is it possible?

+7
source share
3 answers

Yes. You can get the port as follows:

int port = Integer.parseInt(Play.configuration.getProperty("http.port", 9000)); 

Of course you need to import the play.Play class.

+4
source

In Play 2.4.x:

 Play.application().configuration().getString("http.port"); 

or simply:

 System.getProperty("http.port"); 

This only works in production mode when http.port is set via the Java -D parameter.

+2
source

Since the system does not yet give me comments, I am forced to add a comment here.

This Carsten answer should be for play1, for play2, see Extracting the port number in the Play Framework 2 application

+1
source

All Articles