Introduction📑
The emergence of cloud services is one of the primary factors enabling digital transformation. Cloud storage is significantly safer than on-site servers, one of the reasons cloud services have grown so well-liked. A company's data can be easily deployed and saved in the cloud even if a gadget is stolen or damaged.

So, without further ado, let's take a deeper look at the deployment of a Play Application to a Cloud Service and briefly understand the four deployment methods.
Deploying to Heroku🧑💻

Heroku is a platform for building and deploying web applications in the cloud. Heroku is a framework for deploying and operating contemporary apps based on a managed container architecture, integrated data services, and a robust ecosystem.
To begin:
- Setup the Heroku Toolbelt
- Open a Heroku account.
There are two ways to deploy to Heroku:
- Pushing to a distant Git repository
- Using the SBT-Heroku plugin
Deploying to a Remote Git Repository🖥️
Install your program using git
$ git init
$ git add .
$ git commit -m "init"
Make a new Heroku application.
$ heroku create
Creating warm-frost-1289... done, stack is cedar-14
http://warm-frost-1289.herokuapp.com/ | git@heroku.com:warm-frost-1289.git
Git remote heroku added
This creates a new application with your application's HTTP (and HTTPS) and Git endpoints. The Git endpoint configures your Git repository's setup as a new remote called Heroku.
Deploy your program
Use Git to push your application into the Heroku remote repository to deploy it there:
$ git push heroku main
Counting objects: 93, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (84/84), done.
Writing objects: 100% (93/93), 1017.92 KiB | 0 bytes/s, done.
Total 93 (delta 38), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Play 2.x - Scala app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Priming Ivy cache (Scala-2.11, Play-2.4)... done
remote: -----> Running: sbt compile stage
...
remote: -----> Dropping ivy cache from the slug
remote: -----> Dropping sbt boot dir from the slug
remote: -----> Dropping compilation artifacts from the slug
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 93.3MB
remote: -----> Launching... done, v6
remote: https://warm-frost-1289.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/warm-frost-1289.git
* [new branch] main -> main
Heroku will launch sbt stage to get your application ready. All dependencies will be downloaded during the initial deployment, which takes some time to finish (but they will be cached for future implementations).
If your application stalls at this point when using RequireJS:
[info] Optimizing JavaScript with RequireJS
Then try following the instructions in the Heroku Dev Center article Using Node.js to Perform JavaScript Optimization for Play and Scala Applications. The Javascript engine's performance will significantly increase as a result.
Verify the deployment of your application
Let's verify the status of the processes used by the program now:
$ heroku ps
=== web (Free): `target/universal/stage/bin/sample-app -Dhttp.port=${PORT}`
web.1: up 2022/08/14 11:27:51 (~ 5m ago)
The web server is currently operating. To learn more, we can look at the logs:
$ heroku logs
2022-08-13T20:44:49.750860+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2022-08-13T20:44:47.358320+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/myapp -Dhttp.port=${PORT}`
2022-08-13T20:44:52.297033+00:00 app[web.1]: [warn] application - Logger configuration in conf files is deprecated and has no effect. Use a logback configuration file instead.
2022-08-13T20:44:54.960105+00:00 app[web.1]: [info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
2022-08-13T20:44:55.066582+00:00 app[web.1]: [info] play.api.Play$ - Application started (Prod)
2022-08-13T20:44:55.445021+00:00 heroku[web.1]: State changed from starting to up
2022-08-13T20:44:55.330940+00:00 app[web.1]: [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
The logs can also be followed just like a regular file. For troubleshooting, we can use:
$ heroku logs -t --app warm-frost-1289
2015-07-13T20:44:47.358320+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/myapp -Dhttp.port=${PORT}`
2015-07-13T20:44:49.750860+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2015-07-13T20:44:52.297033+00:00 app[web.1]: [warn] application - Logger configuration in conf files is deprecated and has no effect. Use a logback configuration file instead.
2015-07-13T20:44:54.960105+00:00 app[web.1]: [info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
2015-07-13T20:44:55.066582+00:00 app[web.1]: [info] play.api.Play$ - Application started (Prod)
2015-07-13T20:44:55.445021+00:00 heroku[web.1]: State changed from starting to up
2015-07-13T20:44:55.330940+00:00 app[web.1]: [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
...
It looks good. Now, we can access the app by launching:
$ heroku open
Troubleshooting🤯
Heroku will detect the presence of a build.gradle file in your app and attempt to build it as a Gradle project rather than a Scala sbt project. By executing the following command, you may compel Heroku to use using sbt:
$ heroku buildpacks:set heroku/scala
Your repository's build.sbt file will be used by the Scala build pack to create the application.
Deploying Applications that use the most recent Java Versions
Heroku runs Java apps by default with OpenJDK 8. Deploying an application that utilizes a newer version of Java results in a compilation error on the server since it cannot automatically detect whether another version is required. Java 8 and later versions should be declared in your system if you utilize them. in the project root directory's properties file, for instance:
java.runtime.version=11