Project 2C: Bear Maps (Heroku), version 4.0

Deploying on Heroku

Creation of a JAR with dependencies

A JAR with dependencies is a type of JAR that includes all your code from the external libraries (dependencies) used in the project. When we deploy an application on external server we need this kind of JAR which is self-sufficient(does not depend on anything else) and is enough to run the entire code.

An important step for this is to package all the resources, i.e, static data files (images, etc in our case) within this JAR itself.

1. Configuring JAR

Configuring jar

Adding sources 1

Adding sources 2

2. Configuring your code

2.1 Editing Paths

Since we have placed the data directory in the jar itself, we need to change the file paths of our images and other xml files.

Changing paths

2.2 Reading files

Since the files are present in the JAR now, we need to change the way we read them in RasterAPIHandler and StreetMapGraph. To read files from jar we make use of Thread.currentThread().getContextClassLoader().getResource(filePath) and Thread.currentThread().getContextClassLoader().getResource(filePath) functions. These functions help us access content from our resources root.



2.2 Configuring port

Since we are deploying our application on an external server we need to configure the port we want our application to run on.


Building JAR

Testing your JAR

On the terminal, navigate to the path where the JAR was created and run java -jar <jar-name>.jar. Your application should start running and work as it worked when you ran it from IntelliJ. Now we are ready to deploy this on Heroku

Heroku Deployment

Onetime setup steps

Please do not execute these everytime you want to deploy

  1. Setup your free Heroku account here
  2. Install and setup Heroku Command Line Interface (CLI) at
  3. Make sure you have completed log-in steps to Heroku cli using the command heroku login
  4. Run command heroku create bearmaps-<repo-id(For example, bearmaps-sp19-s9999) in the base project directory(proj2c). This will create a Heroku app with the name bearmaps-<repo-id> and would be visible in your Dashboard at

Creating app

  1. Install Heroku deploy plugin using heroku plugins:install heroku-cli-deploy


Deploying app

Checking logs

For more information use the following link:


Unable to read image and/or xml files.

Make sure that the paths are changed correctly and you have included the contents of library-sp19 folder in the jar output, while configuring artifact.

The changes in code are not reflected on Heroku.

Make sure you rebuild the artifact(jar) and redeploy it.