Deploy application on the server
-
Add a application secret to the project. You can do it by adding a property in the application.conf
Example:
play.http.secret.key="changeme"
-
Open the host filter privilege to allow alternative host access by adding a property in the application.conf
This command allow access from any host name:
play.filters.hosts { allowed = ["."] }
-
Add the sbt-native-packager plugin to the project. You can do it by adding a single line of code to the plugins.sbt file.
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0")
-
Add the following line of code to the build.sbt file as well:
enablePlugins(JavaAppPackaging)
-
Run the following command in the root directory of the project
sbt stage
-
This command generates a new folder in your project directory: target/universal/stage/
There are two folders in the stage directory: bin and lib. The first one contains launchers (Linux/Mac/Windows). The second one contains all dependencies and a JAR with the application classes.
The content of the stage directory can be moved to your server and launched there by executing the following command in the console:
./bin/app-name -Dplay.http.secret.key='changeme'
Notice that this command must be run from the stage folder. By the way, app-name may vary. It depends on the project name (package name) that you specified in the build.sbt file.
-
If an alternative http port is required for the server, the command should include the port assignment part.
./bin/app-name -Dhttp.port=port_required -Dplay.http.secret.key='changeme'
-
Application process can be run as daemon.
nohup ./bin/app-name -Dhttp.port=port_required -Dplay.http.secret.key='changeme' &
Reference:
[1]. https://dzone.com/articles/building-and-deploying-scala-apps
[2]. https://www.playframework.com/documentation/2.7.x/ApplicationSecret