Quantcast
Channel: JAVA – Jitendra Zaa's Blog
Viewing all articles
Browse latest Browse all 12

Creating First Application in Heroku using Eclipse

$
0
0

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.

Prerequisites:

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.

Setting up Credentials for Heroku in Eclipse

Setting up Credentials for Heroku in Eclipse


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”.

Generate SSH Key in Eclipse for Heroku

Generate SSH Key in Eclipse for Heroku

Now, after generation of RSA key Navigate to “Heroku” and click on “Load SSH Key” and select file which you have saved recently.

Load SSH Key in Heroku using Eclipse

Load SSH Key in Heroku using Eclipse

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.

Select Application template from new Heroku Project

Select Application template from new Heroku Project

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.

Getting Started with Embedded Jetty in Heroku

Getting Started with Embedded Jetty in Heroku

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:

Commit Changes to Git - Heroku

Commit Changes to Git – Heroku

After Committing the Changes, Navigate to “Right Click on Project | Team | Push to Upstream”.

Push to UpStream in Git for Heroku

Push to UpStream in Git for Heroku

Now, if everything is good, Heroku will receive all you local Changes and build application again on its server.

Heroku Build Succeed

Heroku Build Succeed

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.


Viewing all articles
Browse latest Browse all 12

Trending Articles