1. Download the Heroku Commandline Interface from below link:
https://s3.amazonaws.com/assets.heroku.com/heroku-toolbelt/heroku-toolbelt.exe
now install it with simple steps next next only.
Create account on Heroku with below signup link .
https://signup.heroku.com/dc
Login to Heroku Cloud
Create a Procfile
You declare how you want your application executed in Procfile in the project root. Create this file with a single line:
web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
Commit your changes to Git:
$ git init
$ git add .
$ git commit -m "Ready to deploy"
Create the app:
$ heroku create
Creating high-lightning-129... done, stack is cedar-14
http://high-lightning-129.herokuapp.com/ | git@heroku.com:high-lightning-129.git
Git remote heroku added
Deploy your code:
$ git push heroku master
The application is now deployed. Ensure that at least one instance of the app is running:
$ heroku ps:scale web=1
Congratulations! Your web app should now be up and running on Heroku. Open it in your browser with:
$ heroku open
Git Cloning Existing Heroku Applications
heroku git:clone -a myapp
Replace myapp with the name of your app.
Complete Reference on:
Connect To Database on Heroku
1. create Database
c:\> heroku addons:create heroku-postgresql:hobby-dev
2. Know all details about data plan
heroku pg:info
3 heroku pg:credential
4. Maven add this to your pom.xml:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208</version>
</dependency>
5. connect to database using java
private static Connection getConnection() throws URISyntaxException, SQLException {
String dbUrl = System.getenv("JDBC_DATABASE_URL");
return DriverManager.getConnection(dbUrl);
}
OR
Create a JDBC connection to Heroku Postgres by parsing the DATABASE_URL environment variable.
private static Connection getConnection() throws URISyntaxException, SQLException {
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
return DriverManager.getConnection(dbUrl, username, password);
}
Sharing Heroku Postgres between applications
You can share one Heroku Postgres between multiple applications.
heroku addons:attach webapp1616::DATABASE --app myweb2016
No comments:
Post a Comment