Saturday, May 18, 2019

How to setup SSH keys | How to setup Repo in GitHub and Setup Java Project in GitHub | How to add a Java Web App in GitHub using Maven

GitHub is one of the popular git-based version control systems. GitHub is very good example for Software-as-a-service, hosted on cloud for storing and sharing code. 

We will learn how to create a Java Project using Maven and push Java Project into GitHub from Ec2 instance. Let us learn how to create SSH keys and securely connect to gitHub from EC2 instance. 

Git is a purely distributed version control system. Click here to learn more about Git and its advantages over other SCMs.


Pre-requisites:

1. GitHub account
2. Git client installed
3. Connect to your Jenkins EC2 instance

Step # 1 - Create private repository in GitHub

Click on New to create a new repo 
Also choose initialize with repository with a README option.

Step # 2 Create SSH keys from your Jenkins EC2 machine

Login to your Jenkins EC2 instance using Git bash. (make sure you are connected to Jenkins instance)
Type ssh-keygen (and then click on enter four button times, do not give any password). 
ssh-keygen command will generate two keys - public keys and private keys. We need to upload only the public keys into GitHub.

If you already have keys generated, you can use the existing key, you don't have to overwrite the existing key.


copy the content of public key by executing below command in Git bash:
sudo cat ~/.ssh/id_rsa.pub


Step # 3 - Upload SSH Keys in GitHub

Go to GitHub, click on Settings.
Copy SSH keys Key section and then click on Add SSH key.


Step # 4 - Clone Repo locally

Now click on the Cat icon on your top left to go back to repo you just created.
Click on the repo you created in step # 1, click on Code, under SSH
 




Copy the SSH url and go to your EC2 instance using git bash and perform below command:

git clone <paste the ssh url >

type yes to connect

After you clone, you should see something below:







type below command to list the directory
ls -al
The above command should list the directory you have cloned.

Now go into repo folder(red circled like above) you have cloned.
cd MyApplicationRepo

Step # 5 - Create Java Web App using Maven
use below maven command to create Java Web App using Maven. Maven is the build for creating and building java projects. Click here to know more about Maven.

mvn archetype:generate -DgroupId=com.dept.app -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Step # 6 - Push Java Web App using Git commands into GitHub

type below command to see the new folder called MyWebApp
ls -al

type  below command to see the newly created project in red color
git status

Now add the newly created folder by executing below command:
git add  *

Now make sure all the files are moved to staging area, when you execute below command:
git status

git config --global user.name "your github user_id"
git config --global user.email "youremailid"

Perform below command to commit the changes to local repository first.
git commit -m "my first project check-in to GitHub"

Now perform below command to push from local repository to remote repository. 

git push

 

Verify code changes in GitHub

Now to GitHub and click on the repo, you will see your commits.


You can also watch the videos of the above lab exercise in my YouTube channel given below:




11 comments:

  1. JavaScript’s popularity has soared in recent decades and it has become the de facto language of the web. All browsers implement JavaScript these days making it an essential skill to learn along with HTML and CSS. Any web developer whether working on front-end or back-end applications should learn Javascript to be successful. Javascript is used for developing interactive websites, web applications, mobile apps, desktop apps, designing visual effects and even in game development and IoT. and other similar anchor texts like above

    ReplyDelete
  2. My friend sent me here and I thought I’d say hi, great blog. aprende java

    ReplyDelete
  3. Looking for a gaming platform that offers excitement and rewards? Look no further than Rpjitu deposit 5000. Join now and start winning big!

    ReplyDelete
  4. Your website has become a source of inspiration and encouragement for me, reminding me to stay positive and optimistic in the face of adversity. Markaszeus

    ReplyDelete
  5. Jual alat pemadam kebakaran yang cocok untuk kendaraan, rumah, dan kantor. Proteksi maksimal di mana saja. jual alat pemadam kebakaran

    ReplyDelete
  6. Temukan promo menarik untuk topup diamond FF hanya di sini Topup diamond FF

    ReplyDelete
  7. Temukan slot dengan tema olahraga di master 198

    ReplyDelete
  8. Hokiwin menawarkan permainan dengan RTP tinggi

    ReplyDelete
  9. Temukan permainan slot terbaru dan terpopuler di Mpo303.

    ReplyDelete
  10. Temukan berbagai tema slot menarik di Mpo338 dan menangkan hadiah besar.

    ReplyDelete

What is GitHub Advanced Security for Azure DevOps | Configure GitHub Advanced Security for Azure DevOps

GitHub Advanced Security for Azure DevOps brings the  secret scanning, dependency scanning  and  CodeQL code scanning  solutions already ava...