English 中文(简体)
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:devprototypeactiviti-preso>play run --http.port=8080
[info] Loading project definition from C:devprototypeactiviti-presoproject
[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.
最佳回答

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:

targetuniversalstagein[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]in[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
问题回答

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

Hope this helps someone.

via sbt settings:

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

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.

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.

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

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

For Play 2.3.x

activator "run -Dhttp.port=9001"

Just add the following line in your build.sbt

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

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.

for Play 2.5.x and Play 2.6.x

sbt "-Dhttp.port=9002"

then

run

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

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

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

play> run 8888

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/

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.

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.

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 "%~dp0frameworksbtsbt-launch.jar" %*

so to run on port 9002, do

set PLAY_OPTS=-Dhttp.port=9002
play run

Tested with 2.3.7 Play framework. Works well.

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

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.

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.

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

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.

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

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





相关问题
how do you fix the clients outgoing port number using php?

I m using php (the sockets extension) to handle sending and receiving xml files. I d like to be able to fix the outgoing clients port number as the server has a set amount of incoming connections. I ...

Making a Ruby server work on port 80

I m creating a simple web server in Ruby, which display s the text LOLZ in the browser. I have this now: #!/usr/bin/ruby require socket server = TCPServer.open(2000) loop do client = server....

C# Discover the LocalEndPoint AddressFamily port number

When I establish a tcp connection to a server using the TcpClient class, is there any way to find out the source port of this connection? I am trying to implement the exec protocol and stderr port ...

Listen to a port that is in use [duplicate]

Possible Duplicate: Get connecting IP from specified ports that using by other program. If a port is used by a program, is there any way I can listen that port and get the connected IP on that ...

Can t access locally hosted project via the internet?

I m currently developing a Java Servlet Project in Eclipse. The project is compiled via Tomcat 5.5 and hosted in localhost:8080(alternatively 127.0.0.1:8080 AND 192.168.1.10:8080 which also happens ...

热门标签