Pages

Monday, 30 November 2020

Deploy Your Code to Heroku: Complete Guide (GitHub & Node.js)

Heroku provides a smooth workflow for deploying apps directly from GitHub or via Git. In this guide, you’ll learn both methods step-by-step.

Deploying applications to Heroku is simple once you understand the process. This guide covers:

✔ How to deploy an app to Heroku directly from GitHub
✔ How to deploy a Node.js app to Heroku using Git
✔ Important commands and setup instructions

1. How to Deploy an App to Heroku from GitHub

Follow the steps below:

Step 1: Open Heroku

Login to your Heroku dashboard: https://dashboard.heroku.com/

Step 2: Create a New App

  • Click New → Create new app
  • Enter your app name (example: test)
  • Click Create app

Step 3: Connect to GitHub

  • Go to the Deploy tab
  • Select GitHub under Deployment Method
  • Authorize Heroku (first time only)

Step 4: Select Your GitHub Repository

  • Search repo name
  • Click Connect

Step 5: Enable Auto Deploy (Recommended)

Click Enable Automatic Deploys

Step 6: Deploy the Branch

  • Select branch (main or master)
  • Click Deploy Branch

Step 7: Your App Is Live

You will receive your live URL, for example:
https://test.herokuapp.com


2. How to Deploy a Node.js App to Heroku (Using Git)

Step 1: Create a New App in Heroku

Same as earlier — create a new app in Heroku.

Step 2: Open Terminal

  • VS Code Terminal
  • OR Git Bash in project directory

Step 3: Login to Heroku

heroku login

Step 4: Create a Procfile

touch Procfile

If index.js is in main folder:

web: node index.js

If index.js is inside /src folder:

web: node ./src/index.js

Step 5: Initialize Git

git init

Step 6: Add Heroku Remote

heroku git:remote -a <your-app-name>

Step 7: Push Code to Heroku

git add .
git commit -m "initial deploy"
git push heroku master

Your app will be deployed. You will get your live URL immediately.


Updating the App (Later Changes)

Whenever you update code, run:

git add .
git commit -m "your message"
git push heroku master

Your application will update automatically.


Final Notes

  • Ensure app has a valid package.json
  • Include a proper start script:
"start": "node index.js"
  • Add environment variables in Heroku → Settings → Config Vars

-- Thanks --

Sunday, 29 November 2020

Add Project to GitHub Using Git Base

Add Project to GitHub Using Git Bash (Step-by-Step Guide)

Follow the steps below to upload your local project to GitHub using Git Bash.


1. Create a New Repository on GitHub

  • Open GitHub
  • Click New Repository
  • Enter repository name
  • Click Create Repository

You will now see a set of commands provided for first-time setup.


2. Open Git Bash in Your Project Folder

To open Git Bash at the correct location:

  • Right-click your project folder
  • Select Git Bash Here

OR copy the project path manually:

  • Right-click the project folder
  • Select Properties → Resource → Location
  • Copy the full file path

3. Use the Git Commands Provided by GitHub

Navigate to Your Project Folder

cd "<path>"

Initialize Git

git init

Add GitHub Remote Repository

git remote add origin https://github.com/your-username/your-repo.git

(Use the remote URL shown on your GitHub repository page.)


If “Reinitialized existing Git repository” Appears

This means Git was already initialized earlier. It's better to remove the old Git folder and reinitialize:

rm -rf .git
git init

4. Add All Files to Git

git add .

Note: The dot (.) means add all files from the current folder.


5. Commit Your Changes

git commit -m "first commit"

6. Set Branch Name to main

git branch -M main

7. Push Code to GitHub

git push -u origin main

8. Refresh GitHub Repository

Your project files will now appear on your GitHub repository page.

-- Thanks --

Java | Spring Boot Project | Firebase For Database | GitHub | Heroku To Deploy Project LIVE

STEP 1: Create Spring Boot Web Project

From your IDE:

  • Create New Spring Starter Project

  • Select Web

  • Create packages:

com.example.demo com.example.demo.controller com.example.demo.dbinit com.example.demo.model com.example.demo.service

STEP 2: Initialize Firebase

Create class in dbinit package:

@Service public class InitializeFirebase { @PostConstruct public void initializeFirebase() throws IOException { } }

@PostConstruct ensures the method runs automatically on app startup.


STEP 3: Firebase Login & Firestore Setup

  • Open Firebase Console

  • Choose Cloud Firestore

  • Click Start Collection

  • Collection ID: beginner

  • Document ID: anything (e.g., xyz123)

  • Field example:
    id = "xyz123"

Document ID can be auto-generated or same as your model's ID.


STEP 4: Firestore Connection Code

Go to:

Project Settings → Service Accounts → Java → Generate Code

Copy the code snippet provided.


STEP 5: Initialize Firebase in Project

Paste code inside initializeFirebase():

@PostConstruct public void initializeFirebase() throws IOException { FileInputStream serviceAccount = new FileInputStream("AAAAAAA.json"); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount)) .setDatabaseUrl("https://BBBBBBB.com") .build(); FirebaseApp.initializeApp(options); }

STEP 6: Add Firebase Dependencies

  • Go to Maven Repository

  • Search firebase-admin

  • Use a compatible version (example: 6.11.0)

  • Add in pom.xml

  • Import Firebase classes


STEP 7: Generate Private Key

In Service Accounts:

  • Click Generate New Private Key

  • Download the .json file

  • Paste it inside the project root

  • Replace:

FileInputStream serviceAccount = new FileInputStream("./<filename>.json");

STEP 8: Create Model – Student

Fields:

id name age place

Generate:

  • constructors

  • getters/setters

  • toString()


STEP 9: Create home.jsp

Path: src/main/webapp/home.jsp

<form action="/save"> id: <input type="text" name="id" value="1000"><br> name: <input type="text" name="name"><br> age: <input type="text" name="age"><br> place: <input type="text" name="place"><br> <input type="submit" value="save"> </form>

STEP 10: Controller Setup

@Controller public class StudentController { @RequestMapping("/") public String home() { return "home.jsp"; } }

STEP 11: Add Tomcat Jasper (for JSP)

If page doesn’t load, add Tomcat Jasper:

  • Search tomcat-embed-jasper

  • Version must match tomcat-embed-core

  • Add dependency to pom.xml


STEP 12: Relaunch Project

Now JSP loads properly at:

http://localhost:8080/

STEP 13: Controller Save Method

@RequestMapping("/save") public String saveStudent(Student student) { System.out.println("successfully saved"); return "home.jsp"; }

Console prints "successfully saved" → Controller working.


STEP 14: Create Service Class

@Service public class StudentService { public static void saveStudent(Student student) { } }

STEP 15: Firebase Code to Save Data

public static void saveStudent(Student student) { Firestore dbFirestore = FirestoreClient.getFirestore(); ApiFuture<WriteResult> future = dbFirestore .collection("beginner") .document(student.getId()) .set(student); }

STEP 16: Call Service From Controller

@RequestMapping("/save") public String saveStudent(Student student) { StudentService.saveStudent(student); System.out.println("successfully saved"); return "home.jsp"; }

STEP 17: Add Data to Firebase

  • Relaunch project

  • Submit form

  • Check Firestore
    → Data stored successfully


STEP 18: Push Project to GitHub

Commands:

cd "<path>" git init git remote add origin <repo-link> # If reinitialized rm -rf .git git init git add . git commit -m "first commit" git branch -M main git push -u origin main

STEP 19: Deploy Spring Boot App to Heroku

  1. Login to Heroku

  2. Create New App
    Example: test

  3. Connect to GitHub

  4. Authorize (first time only)

  5. Select repository

  6. Enable Automatic Deploy

  7. Click Deploy Branch

  8. After deployment → Heroku gives URL

Example:

https://test.herokuapp.com/

Your project is now LIVE.


✔ End

-- Thanks --

Friday, 27 November 2020

Create Runnable JAR File And Run It By CMD

How To Create A Runnable JAR File And Run This JAR File By Command Prompt.

step 1: Runnable jar file.

step 2: Run jar file by command prompt.


Runnable jar file

Tuesday, 10 November 2020

Run CMD In Background

How To Run Command Prompt In Background By Java Code?

Follow the instructions:

  • First take a ProcessBuilder object with parameters("cmd.exe","/c","assoc")
    • Put required command instead of "assoc".
  • Give directory name (System.getProperty("user.dir")).
  • Defining true to redirectErrorStream() is recommended
  • Now call start method via ProcessBuilder object.

    Following code can be used to run cmd in backgound and read/print output.

public class Main {
	public static void main(String[] args) throws IOException {
		ArrayList<String> output =  new ArrayList<String>();
		boolean executionStatus=false;
		
		String myDirectory = System.getProperty("user.dir"); 	
		try {
			ProcessBuilder pbuilder = new ProcessBuilder("cmd.exe","/c","assoc");
			pbuilder.directory(new File(myDirectory));
			pbuilder.redirectErrorStream(true);
			Process process = pbuilder.start();
            
		//Reading Output
			BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
			String line;
			while(true) {
				line = reader.readLine();
				if(line==null)break;
				output.add(line);			
			}
			executionStatus = true;
		} catch (Exception e) {
			e.printStackTrace();
			executionStatus = false;
		}
        
		System.out.println("executionStatus : "+executionStatus);
		System.out.println("output:");
		for(String x:output)
			System.out.println(x);
	}
}

For running Command Prompt directly but not in background, Following code can be used:
Runtime.getRuntime().exec(new String[] {"cmd", "/K", "Start"});

Tuesday, 3 November 2020

Executable File From Runnable Jar File

HOW TO CREATE AN .EXE FILE ?

Make sure the project is compiled and run properly. 

Step 1:    Make runnable jar file of project.

Step 2:    Use Launch4j to configure.

Step 3:    Save configuration.

Step 4:    Build Wrapper.

Here we have taken a java project built in Eclipse IDE. Go to the project in Eclipse IDE.


Runnable jar file

click here to get Runnable jar file.


           

Software Required

Now we need a software named Launch4j

1.    Install Launch4j

2.    Extract zip file.

3.    Run Launch4j.exe


 

Create .exe file

1.    Start Launch4j software

2.    Go to Basic tab.

3.    In Output file section

            a.    Browse project folder in workspace

            b.    Named the file as myschedule.exe

4.    In Jar section

        a.    Browse myshedule.jar (previously created jar file).


5.    As per requirement Classpath and Header tabs can be configured.

6.    Go to Single instance tab.

a.    Select Allow only a single instance of the application

                                          i.    Selection will make sure, there will be a single window of application running at a time.

b.    Fill up the Mutex name

                                          i.    Here myschedule given to mutex name

                                         ii.    You should also give a window title.


7.    Go to JRE tab

a.    Here you can provide Min JRE version to the executable environment.

b.    Our project built in 1.8.0, so it is filled up.


8.    As per requirement Set env. variables and Splash tabs can be configured.

9.    Go to Version Info tab.

a.    You can customize as per your requirements

b.    Select Add version information.

c.     File version: 1.0.0.0

                                          i.    Make sure format of version looks like x.x.x.x

d.    Free form: 1.0.0.0

e.    File description: myschedule

                                          i.    you can describe your project here.

f.      Copyright: 2020


g.    Addition information

h.    Product version: 1.0.0.0

i.      Free form: 1.0.0.0

j.      Product name: myschedule

k.     Company name: Uniconverge Technologies Pvt. Ltd.

l.      Internal name: myschedule

m.   Original filename: myschedule.exe

                                          i.    Extension in compulsory here

 

10.  In Messages tab some messages can be given for the particular event.

11.  Now click Save icon


 

a.    Go to the project folder

b.    Make a folder Launch4j config

c.     Enter the Launch4j config folder

d.    Name the file config

e.    Save it

12.  Click Build wrapper (setting icon)


13.  You will see a message in log

a.    Successfully created


14.  myschedule.exe is created in project folder


15.  If you double click on myschedule.exe, you can see your project is running properly.


- - Thanks - -

Deploy Your Code to Heroku: Complete Guide (GitHub & Node.js)

Heroku provides a smooth workflow for deploying apps directly from GitHub or via Git. In this guide, you’ll learn both methods step-by-step....