[playframework] How do I change the default port (9000) that Play uses when I execute the "run" command?

How can I change the default port used by the play framework in development mode when issueing the "run" command on the play console.

This is for playframework 2.0 beta.

Using the http.port configuration parameter either on the command line or in the application.conf seems to have no effect:

C:\dev\prototype\activiti-preso>play run --http.port=8080
[info] Loading project definition from C:\dev\prototype\activiti-preso\project
[info] Set current project to activiti-preso (in build file:/C:/dev/prototype/activiti-preso/)


Windows, really? Ok, disabling colors.

--- (Running the application from SBT, auto-reloading is enabled) ---

[error] org.jboss.netty.channel.ChannelException: Failed to bind to: 0.0.0.0/0.0.0.0:9000
[error] Use 'last' for the full log.

This question is related to playframework port playframework-2.0

The answer is


Play 2.2.0 on Windows

Using a zip distribution (produced using the "dist" command), the only way I was able to change the startup port was by first setting JAVA_OPTS and then launching the application.

E.g., from the command line

set JAVA_OPTS=-Dhttp.port=9002
bin\myapp.bat

where myapp.bat is the batch file created by the "dist" command.

The following would always ignore my http.port parameter and attempt to start on the default port, 9000

bin\myapp.bat -Dhttp.port=9002

However, I've noticed that this works fine on Linux/OSX, starting up on the requested port:

./bin/myapp -Dhttp.port=9002

I did this. sudo is necessary.

$ sudo play debug -Dhttp.port=80
...
[MyPlayApp] $ run

EDIT: I had problems because of using sudo so take care. Finally I cleaned up the project and I haven't used that trick anymore.


Tested with 2.3.7 Play framework. Works well.

./{application}/bin/{executable} -Dhttp.port=5000

On Windows maybe the play "run 9001" will not work. You have to change the play.bat file. See Ticket


for Play 2.5.x and Play 2.6.x

sbt "-Dhttp.port=9002"

then

run

You can also set the HTTP port in .sbtopts in the project directory:

-Dhttp.port=9001

Then you do not have to remember to add it to the run task every time.

Tested with Play 2.1.1.


Play 2.0-RC4

It is important to include quotes around the play command you want to run. In my case without the quotes play would still run on port 9000.

play "run 8080"

Alternatively you could run the following from the play console (type 'play' to get to the console)

run 8080

From the play console, you just need to type run 8888, if you want to run it from port 8888.

play> run 8888

With the commit introduced today (Nov 25), you can now specify a port number right after the run or start sbt commands.

For instance

play run 8080 or play start 8080

Play defaults to port 9000


Specify Port in Development

By default, SBT runs the application on port 9000:

sbt run

To specify a port add -Dhttp.port flag, for example:

sbt run -Dhttp.port=8080

Using the -Dhttp.port flag, you can debug multiple applications on your development machine. Please note, you can also use the -Dhttp.port flag in test and production environments.


Hope this helps someone.

via sbt settings:

...
.settings(PlayKeys.playDefaultPort := 8855)
...

You can set it, with other options, in a .jvmopts file inside the project root directory:

-Dhttp.port=9100

You can also add other options, like loading a different config file with

-Dconfig.file=<config_file_absolute_path>

After you set your .jvmopts file you don't have to remember to add some parameters to the command line, but just do:

sbt run

For Play 2.2.x on Windows with a distributable tar file I created a file in the distributable root directory called: {PROJECT_NAME}_config.txt and added:

-Dhttp.port=8080

Where {PROJECT_NAME} should be replaced with the name of your project. Then started the {PROJECT_NAME}.bat script as usual in the bin\ directory.


Version 2.0.3 :

  • Go to the project directory and just say play (and nothing after that). That will open the play console.

  • Next, say run 8080. That will start play on port 8080.

I hope this helps.


I noticed no one has mentioned achieving this through environment variables (CI/CD friendly).

export PLAY_HTTP_PORT=1234
export PLAY_HTTPS_PORT=1235

Once set, Play will read from those environment variables to determine the port when doing sbt run, sbt start, or when running the executable for prod deployment. See the docs for more.


for play 2.5.x

Step 1: Stop the netty server (if it is running) using control + D

Step 2: go to sbt-dist/conf

Step 3: edit this file 'sbtConfig.txt' with this

-Dhttp.port=9005

Step 4: Start the server

Step 5: http://host:9005/


Just add the following line in your build.sbt

PlayKeys.devSettings := Seq("play.server.http.port" -> "8080")


For Play 2.3.x

activator "run -Dhttp.port=9001"


We are using Play version 2.5.6.

For changing the port, go to your project root folder and hit: activator "run 8008" in command prompt / terminal.

and that's it.


We cannot change the application port from the avtivator but can change from the command line activator "~run 8080"

But to run on the poet 9000 from the activator we need to stop the application which is using this port. We can use the this application to find this and end the process https://technet.microsoft.com/en-in/sysinternals/bb897437.aspx

After this we can run and it will be successful.


On windows, I use a start.bat file like this:

java -Dhttp.port=9001 -DapplyEvolutions.default=true -cp "./lib/*;" play.core.server.NettyServer "."

The -DapplyEvolutions.default=true tells evolution to automatically apply evolutions without asking for confirmation. Use with caution on production environment, of course...


Play 2.2.1 on Windows supports a PLAY_OPTS environment variable. Play's play.bat file contains this line:

java -Dsbt.ivy.home="%~dp0repository" -Dplay.home="%~dp0framework" -Dsbt.boot.properties="%fp%framework/sbt/play.boot.properties" %PLAY_OPTS% -jar "%~dp0framework\sbt\sbt-launch.jar" %*

so to run on port 9002, do

set PLAY_OPTS=-Dhttp.port=9002
play run