Hello Readers, in this article we will see step by step procedure to deploy your first (Hello World) program in Heroku. There are two ways, first going through series of Commands of “Heroku” and “GIT” and other simple and smart way is to use Eclipse Capability with Heroku. To make things easier we will go by second method.
!Deprecated!
This tool / blog post is deprecated. Please follow this guide to deploying applications to Heroku from Eclipse. If you still want to follow this post, then download Eclipse plugin for Heroku from here.
Prerequisites:
- Heroku Account, you can sign up here – https://api.heroku.com/signup/devcenter
- Eclipse 3.7 or Higher
- E-Git Plugin , more information on set up of E-Git – https://jitendrazaa.com/blog/salesforce/salesforce-git-eclipse-egit-better-and-distributed-source-control/
Installation and Set up:
First we will need to Install Heroku Plugin in Eclipse. To install it, Navigate to “Help | Install New Software” and click on “Add” button.
Give any name in website like “Heroku Plugin” and enter this URL in Location https://eclipse-plugin.herokuapp.com/install and click on “Ok” and Finish Installation. It will install the Heroku Plugin required to start your first Plugin.
Next step is setting up your Credentials for Heroku :
Navigate to “Window | Preferences | Heroku”, Here either enter your UserName and Password of Heroku Account and click on “Login” or enter you API key, which you can find by logging into your Heroku Account.
Creating SSH Key :
Heroku uses Git to push and pull code from Heroku. For this you can use E-Git plugin of Eclipse. You can also visit this article for complete tutorial. So, for communication between Heroku and Git we need SSH. Navigate to “Windows | Preferences |General | Network Connections | SSH2 “. Navigate to “Key Management“ tab and click on “Generate RSA Key”. After Generation of key click on “Save Private Key”.
Now, after generation of RSA key Navigate to “Heroku” and click on “Load SSH Key” and select file which you have saved recently.
Now, till this we have done all the configurations. Start with creating our first “Hello World” program from Template using Jetty.
Navigate to “New | Project | Heroku | Create Heroku App from Template” and click on Next.
On Next screen select “Embedded Jetty-Servlet application” and click on Finish. After creation of sample project, open “Main.java” file and run it.
Now open browser with URL http://localhost:8080/ and you should able to see Jetty Page. If you are able to see the Jetty Startup page, means everything is good. Now navigate to http://localhost:8080/hello , you will see text “Hello Heroku” just like below screen.
You can make modifications in “HelloServlet.java” by replacing below line with some other Text.
<br />out.write("Hello Heroku".getBytes());<br />
Deploying Modifications to Heroku from Local System:
Now, as we are done with making modifications in local code, commit the changes in Git by “Right Click on Project | Team | Commit”. You need to Enter Commit Message like this:
After Committing the Changes, Navigate to “Right Click on Project | Team | Push to Upstream”.
Now, if everything is good, Heroku will receive all you local Changes and build application again on its server.
Now you can run this application by logging into Heroku and make modifications that’s suits you like Salesforce Integration or any other.
You can also visit this official Heroku tutorial, which explains in very detail about Heroku Deployment using Eclipse and other important Configurations.
If you are getting an error “eclipse SSH key is not matching the SSH key(s) that is associated with your Heroku account“, then follow this article to resolve this.
Leave a Reply