Herokuapp - develop and deploy your app on it


  • a free Heroku account.
  • Java 8 installed locally.
  • Maven 3 installed locally.

Set up

  • install the Heroku Toolbelt
  • heroku login

Prepare the app

$ git clone https://github.com/heroku/java-getting-started.git
$ cd java-getting-started

Deploy the app

Create an app on Heroku, which prepares Heroku to receive your source code:

$ heroku create
Creating blooming-badlands-89943... done, stack is cedar-14
http://blooming-badlands-89943.herokuapp.com/ | https://git.heroku.com/blooming-badlands-89943.git
Git remote heroku added

Now deploy your code:

$ git push heroku master
Initializing repository, done.
Counting objects: 68, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (68/68), 7.07 KiB | 0 bytes/s, done.
Total 68 (delta 22), reused 65 (delta 22)

-----> Java app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Maven 3.3.1... done
-----> Executing: mvn -B -DskipTests=true clean install

       [INFO] Scanning for projects...
       [INFO] ------------------------------------------------------------------------
       [INFO] Building helloworld 1.0-SNAPSHOT
       [INFO] ------------------------------------------------------------------------
-----> Discovering process types
       Procfile declares types -> web

-----> Compressing... done, 62.7MB
-----> Launching... done, v7
       http://blooming-badlands-89943.herokuapp.com/ deployed to Heroku

To git@heroku.com:blooming-badlands-89943.git
 * [new branch]      master -> master

Ensure that at least one instance of the app is running:

 $heroku ps:scale web=1

Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:

 $ heroku open


View logs

 $ heroku logs --tail
 2016-03-31T08:44:45.008841+00:00 heroku[web.1]: Starting process with command `java -cp target/classes:target/dependency/* Main`
 2016-03-31T08:44:47.941949+00:00 app[web.1]: [Thread-0] INFO spark.webserver.SparkServer - == Spark has ignited ...
 2016-03-31T08:44:47.949901+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.0.2.v20130417
 2016-03-31T08:44:47.946093+00:00 app[web.1]: [Thread-0] INFO spark.webserver.SparkServer - >> Listening on
 2016-03-31T08:44:48.280107+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@42d76c7c{HTTP/1.1}{}
 2016-03-31T08:44:48.703339+00:00 heroku[web.1]: State changed from starting to up

Define a Procfile

 web: java $JAVA_OPTS -cp target/classes:target/dependency/* Main

Scale the app

$ heroku ps
=== web (Free): `java $JAVA_OPTS -cp target/classes:target/dependency/* Main`
web.1: up 2016/03/31 14:55:07 (~ 2m ago)

Declare app dependencies



install locally

mvn clean install

Run the app locally

$ heroku local web
[WARN] No ENV file found
[OKAY] Trimming display Output to 61 Columns
9:26:12 AM web.1 |  [Thread-0] INFO spark.webserver.SparkServer - == Spark has ig…
9:26:12 AM web.1 |  [Thread-0] INFO spark.webserver.SparkServer - >> Listening on…
9:26:12 AM web.1 |  [Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.0.2…
9:26:12 AM web.1 |  [Thread-0] INFO org.eclipse.jetty.server.ServerConnector - St…

Open http://localhost:5000


Written on March 31, 2016