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

PlayframeworkPortPlayframework 2.0

Playframework Problem Overview


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.

Playframework Solutions


Solution 1 - Playframework

Play 2.x

> In Play 2, these are implemented with an sbt plugin, so the following instructions are really just sbt tasks. You can use any sbt runner (e > In Play 2, these are implemented with an sbt plugin, so the following are really just > sbt tasks. You can use any sbt runner (e.g. sbt, play, or > activator). Below the sbt runner is used, but > you can substitute it for your sbt runner of choice.

Play 2.x - Dev Mode

For browser-reload mode:

sbt "run 8080"

For continuous-reload mode:

sbt "~run 8080"

Play 2.x - Debug Mode

To run in debug mode with the http listener on port 8080, run:

sbt -jvm-debug 9999 "run 8080"

Play 2.x - Prod Mode

Start in Prod mode:

sbt "start -Dhttp.port=8080"

Play 2.x - Staged Distribution

Create a staged distribution:

sbt stage

For Play 2.0.x and 2.1.x use the target/start script (Unix Only):

target/start -Dhttp.port=8080

For Play 2.2.x & 2.3.x use the appropriate start script in the target/universal/stage/bin directory:

target/universal/stage/bin/[appname] -Dhttp.port=8080

With Play 2.2.x & 2.3.x on Windows:

target\universal\stage\bin\[appname].bat -Dhttp.port=8080

Play 2.x - Zip Distribution

To create a zip distribution:

sbt dist

For Play 2.0.x and 2.1.x use the start script (Unix Only) in the extracted zip:

start -Dhttp.port=8080

For Play 2.2.x use the appropriate script in the [appname]-[version]/bin directory:

[appname]-[version]/bin/[appname] -Dhttp.port=8080

With Play 2.2.x on Windows:

[appname]-[version]\bin\[appname].bat -Dhttp.port=8080

Play 1.x

Change the http.port value in the conf/application.conf file or pass it command line:

play run --http.port=8080

Solution 2 - Playframework

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

Solution 3 - Playframework

Hope this helps someone.

via sbt settings:

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

Solution 4 - Playframework

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.

Solution 5 - Playframework

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.

Solution 6 - Playframework

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

Solution 7 - Playframework

For Play 2.3.x

activator "run -Dhttp.port=9001"

Solution 8 - Playframework

Just add the following line in your build.sbt

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

Solution 9 - Playframework

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.

Solution 10 - Playframework

for Play 2.5.x and Play 2.6.x

sbt "-Dhttp.port=9002"

then

run

Solution 11 - Playframework

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

Solution 12 - Playframework

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

Solution 13 - Playframework

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

play> run 8888

Solution 14 - Playframework

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/

Solution 15 - Playframework

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.

Solution 16 - Playframework

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.

Solution 17 - Playframework

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

Solution 18 - Playframework

Tested with 2.3.7 Play framework. Works well.

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

Solution 19 - Playframework

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.

Solution 20 - Playframework

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.

Solution 21 - Playframework

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...

Solution 22 - Playframework

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.

Solution 23 - Playframework

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

Solution 24 - Playframework

In version 2.8.X you can run with specific resource file or specific port (if just sbt run, you will use application.conf and defautl port 9000)

sbt run -Dconfig.resource=application.Local.conf -Dhttp.port=9002

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBoris TerzicView Question on Stackoverflow
Solution 1 - PlayframeworkJames WardView Answer on Stackoverflow
Solution 2 - PlayframeworkJonathan DixonView Answer on Stackoverflow
Solution 3 - PlayframeworkArminView Answer on Stackoverflow
Solution 4 - PlayframeworkShashank AraokarView Answer on Stackoverflow
Solution 5 - PlayframeworkWextuxView Answer on Stackoverflow
Solution 6 - PlayframeworkJason BassView Answer on Stackoverflow
Solution 7 - PlayframeworksumitaroraView Answer on Stackoverflow
Solution 8 - PlayframeworkNitin AggarwalView Answer on Stackoverflow
Solution 9 - PlayframeworklachdracheView Answer on Stackoverflow
Solution 10 - PlayframeworkMesut YiğitView Answer on Stackoverflow
Solution 11 - PlayframeworkOlivier RefaloView Answer on Stackoverflow
Solution 12 - PlayframeworkPaddyView Answer on Stackoverflow
Solution 13 - PlayframeworkSiddhuView Answer on Stackoverflow
Solution 14 - PlayframeworkbobbyView Answer on Stackoverflow
Solution 15 - PlayframeworkLineDropView Answer on Stackoverflow
Solution 16 - PlayframeworkWildhammerView Answer on Stackoverflow
Solution 17 - PlayframeworkIanRaeView Answer on Stackoverflow
Solution 18 - PlayframeworkVenkateshView Answer on Stackoverflow
Solution 19 - PlayframeworkFerran MaylinchView Answer on Stackoverflow
Solution 20 - PlayframeworkSwapnil KaduView Answer on Stackoverflow
Solution 21 - PlayframeworkopensasView Answer on Stackoverflow
Solution 22 - PlayframeworkAvinav MishraView Answer on Stackoverflow
Solution 23 - PlayframeworkAtropoView Answer on Stackoverflow
Solution 24 - PlayframeworkcyrilView Answer on Stackoverflow