How to change the http port for play framework 2.4.1?
Asked Answered
J

5

3

I come from a play 1.2.7 application and currently getting started with play framework 2.4.1 and scala. For a start I use the activator web ui to manage applications and there I cannot get the application to use a different http port.

I changed the http.port setting in conf/application.conf, but still play 2.4.1 tries to bind to port 9000, which is already in use. The setting I tried is:

http.port=7000

Any suggestion on how to change the port for a play framework 2.4.1 application that is run via the activator web ui?

Note that as suggested in the linked question I can use

./activator "run 7000"

in the application itself to have it bind to port 7000. Still my question is how can I get the same behaviour via the activator web ui?

Juta answered 1/7, 2015 at 9:23 Comment(3)
possible duplicate of How do I change the default port (9000) that Play uses when I execute the "run" command?Isthmian
playframework.com/documentation/2.4.x/ProductionConfigurationMarolda
I followed the documentation and added http.port to application.conf, it just doesn't seem to be used. I don't use the play run method right now, but activator's web ui.Juta
D
1

Add the following to build.sbt of your project where <port> should be replaced with your desired port number.

build.sbt

fork in run := true
javaOptions in run += "-Dhttp.port=<port>"

Expected console output in Activator UI on run

Setting up Play fork run ... (use Ctrl+D to cancel)

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

p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:<port>

(Server started, use Ctrl+D to stop and go back to the console...)
Damondamour answered 9/7, 2015 at 20:53 Comment(2)
I've tried to do this and it doesn't work. I tried starting it with activator and with sbt, and neither picked up the optionTenstrike
This solution is solely for starting applications via Activator Web UI (activator ui). If you want to change the port when using sbt or activator command line just add -Dhttp.port=<port> to your command (e.g. activator run -Dhttp.port=8080)Damondamour
V
10

Through the application.conf in production:

play.server.http.port = 80

When you run the application with SBT:

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

Using run command:

$ run 80

For more details please refer the below links:

documentation-Config File

documentation-Server configuration options

Vegetation answered 27/3, 2016 at 9:55 Comment(1)
It's never too late to give some effort to answer a question!Calix
D
1

Add the following to build.sbt of your project where <port> should be replaced with your desired port number.

build.sbt

fork in run := true
javaOptions in run += "-Dhttp.port=<port>"

Expected console output in Activator UI on run

Setting up Play fork run ... (use Ctrl+D to cancel)

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

p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:<port>

(Server started, use Ctrl+D to stop and go back to the console...)
Damondamour answered 9/7, 2015 at 20:53 Comment(2)
I've tried to do this and it doesn't work. I tried starting it with activator and with sbt, and neither picked up the optionTenstrike
This solution is solely for starting applications via Activator Web UI (activator ui). If you want to change the port when using sbt or activator command line just add -Dhttp.port=<port> to your command (e.g. activator run -Dhttp.port=8080)Damondamour
C
0

Just a short note concerning the run command (tested with Play! 2.4):

At least on Windows activator run -Dhttp.port=80 does NOT work, but activator (hit enter) and then run -Dhttp.port=80 works

Cartogram answered 25/4, 2016 at 9:2 Comment(1)
You'll have to use quotes when passing parameters to activator (or sbt): activator "run -Dhttp.port=80", otherwise each parameter is assumed to be a task and run separately. When running the activator (or sbt) console, you can omit the quotes.Naga
A
0

Try this out:

activator "run 9500"

in terminal from your project folder.

Aleppo answered 23/9, 2016 at 10:18 Comment(0)
I
0

This command work for me guys:

activator "~run 3333"
Inchoation answered 25/10, 2017 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.