8

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?

chuuk
  • 353
  • 6
  • 13
  • 1
    You should at least point which version of Play are you using, I assume that getting working port on version 1 and 2 will be different. – biesior Jun 24 '12 at 19:25

3 Answers3

4

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.

Carsten
  • 17,991
  • 4
  • 48
  • 53
2

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.

raoulsson
  • 14,978
  • 11
  • 44
  • 68
1

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

Community
  • 1
  • 1
Gonfi den Tschal
  • 1,754
  • 1
  • 20
  • 29