Heroku

    For using Heroku, you will need Java, Maven/Gradle and the Heroku CLI

    You will also need to configure your public key in the Heroku configuration.

    You can try the command to see if you have the command line installed:

    You will also need an app.json file describing your projects and your dependencies:

    1. {
    2. "name": "Start on Heroku: Kotlin",
    3. "description": "A barebones Kotlin app, which can easily be deployed to Heroku.",
    4. "image": "heroku/java",
    5. "addons": [ "heroku-postgresql" ]
    6. }

    You will also need a Procfile describing what to execute:

    1. web: java -jar target/helloworld.jar
    1. java.runtime.version=1.8

    And a file called .env along with the other files(required for development).This will contain environment variables that Heroku will pass to the application.For example, for the quickstart:

    If your local installation of postgresql has a user/password, you have to change the jdbc url too:

    1. JDBC_DATABASE_URL=jdbc:postgresql://localhost:5432/java_database_name?user=user&password=password

    You will also first need to create the database:

    1. > psql -c "CREATE DATABASE java_database_name;"
    2. CREATE DATABASE

    With these files, you can use Gradle or Maven to create a and adjust the Procfileto point to the right file.

    After building the jar, in Unix systems you can use heroku local:start to start your server.

    1. > heroku create

    This effectively adds a heroku remote to your git clone:

    After that, you have to push your git changes to the heroku remote. And it does a build on push:

    1. > git push heroku master
    2. Counting objects: 90, done.
    3. Delta compression using up to 4 threads.
    4. Compressing objects: 100% (59/59), done.
    5. Writing objects: 100% (90/90), 183.08 KiB | 5.55 MiB/s, done.
    6. Total 90 (delta 21), reused 0 (delta 0)
    7. remote: Compressing source files... done.
    8. remote: Building source:
    9. remote:
    10. remote: -----> Java app detected
    11. remote: -----> Installing JDK 1.8... done
    12. remote: -----> Executing: ./mvnw -DskipTests clean dependency:list install
    13. ...
    14. remote: [INFO] BUILD SUCCESS
    15. remote: [INFO] ------------------------------------------------------------------------
    16. remote: [INFO] Total time: 49.698 s
    17. remote: [INFO] Finished at: 2018-03-23T04:33:01+00:00
    18. remote: -----> Discovering process types
    19. remote: Procfile declares types -> web
    20. remote:
    21. remote: -----> Compressing...
    22. remote: Done: 60.7M
    23. remote: -----> Launching...
    24. remote: Released v4
    25. remote: https://demo-demo-12345.herokuapp.com/ deployed to Heroku
    26. remote:
    27. remote: Verifying deploy... done.
    28. To https://git.heroku.com/demo-demo-12345.git
    29. * [new branch] master -> master

    Now you can execute heroku open to open your application in your browser:

    1. heroku open

    In this case, it will open: https://demo-demo-12345.herokuapp.com/

    If you encountered:

    1. remote: ! ERROR: Failed to run Gradle!
    2. remote: It looks like your project does not contain a 'stage' task, which Heroku needs in order
    3. remote: to build your app.

    Remember that Heroku sets an environment variable called PORT which you have to bind to instead ofa fixed port.When using embeddedServer you will have to use System.getenv, while when using application.conf you willhave to set ktor.deployment.port = ${PORT}.Check out the page aboutfor more information.