Friday, 21 August 2020

How to install Maven and Java JDK in windows and mac

To install Apache Maven on Windows, you just need to download the Maven’s zip file, unzip it to a folder, and configure the Windows environment variables.

Tested with :

1.       JDK 10

2.       Maven 3.6

3.       Windows 10

Note

1.       Maven 3.3+ requires JDK 1.7+

2.       Maven 3.2 requires JDK 1.6+

3.       Maven 3.0/3.1 requires JDK 1.5+

1. JDK and JAVA_HOME

Make sure JDK is installed, and JAVA_HOME environment variable is configured. To download Open JDK go to

https://jdk.java.net/14/

Direct Download: https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_windows-x64_bin.zip

Extract the zip file to a folder: Eg C:\Program Files\jdk-14.0.2

 

 

Next in the windows search Type Edit Enviroment Variables---

 

Enter Variable: JAVA_HOME  Value: your_file_path_to_java_folder

 


 

 

 

2. Download Apache Maven

2.1 Visit Maven official website, download the Maven zip file, for example : apache-maven-3.6.0-bin.zip.

 

2.2 Unzip it to any folder

Note
That’s all, just download and unzip, installation is NOT required.

3. Add MAVEN_HOME system variable

Add a MAVEN_HOME system variables, and point it to the Maven folder.

3.1 Press Windows key, type adva and clicks on the View advanced system settings

3.2 In System Properties dialog, select Advanced tab and clicks on the Environment Variables... button.

3.3 In “Environment variables” dialog, System variables, Clicks on the New... button and add a MAVEN_HOME variable and point it to c:\opt\apache-maven-3.6.0

 

4. Add %MAVEN_HOME%\bin To PATH

In system variables, find PATH, clicks on the Edit... button. In “Edit environment variable” dialog, clicks on the New button and add this %MAVEN_HOME%\bin

REPEAT SAME for %JAVA_HOME%\bin

 

 

5. Verification

Done, start a new command prompt, type mvn –version :

C:\Users\mkyong>mvn -version

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)

Maven home: C:\opt\apache-maven-3.6.0\bin\..

Java version: 10.0.1, vendor: Oracle Corporation, runtime: C:\opt\Java\jdk-10

Default locale: en_MY, platform encoding: Cp1252

OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

 

C:\Users\mkyong>echo %MAVEN_HOME%

C:\opt\apache-maven-3.6.0

Copy

The Apache Maven is installed successfully on Windows.

6. FAQs

6.1 ‘mvn’ is not recognized as an internal or external command?

> mvn -version

'mvn' is not recognized as an internal or external command,

operable program or batch file.

Copy

Answer: Refer to Step 4, make sure the %MAVEN_HOME%\bin is added to the PATH system variable.

6.2 The JAVA_HOME environment variable is not defined correctly

> mvn -version

The JAVA_HOME environment variable is not defined correctly

This environment variable is needed to run this program

NB: JAVA_HOME should point to a JDK not a JRE

 Note: For MAC Users please use the below links

https://java.tutorials24x7.com/blog/how-to-install-openjdk-14-on-mac

https://javabydeveloper.com/how-to-install-maven-on-mac-osx/

Watch Video for Mac




Watch Video for Windows





Wednesday, 19 August 2020

How to setup SSH keys in Bitbucket and Set up Java Web App using Maven in Bitbucket

 We will see how to setup Java Web App using Maven in BitBucket and also how to setup SSH keys in Bitbucket.


Pre-requistes:
If you don't have an bitbucket account, You need to create an account in bitbucket.org.
Implementation steps:

1. after login into bitbucket, click on + and Click on Create Repository


2. enter the repo name as MyBitbucketRepo, make sure it is private, Include read me option - choose yes with template. Click Git as version control system.
3. Click on create repository.
4. now click on your avatar (left bottom of the screen, BitBucket settings-> security--> ssh keys


5. now go to your laptop, open git bash for windows laptop
6. Now type  ssh-keygen (and then simply enter four times, do not give any password)




 




7. copy the content of public key executing below command in Gitbash.

cat ~/.ssh/id_ed25519.pub 

 

8. go to click on Add key from step # 3,  and paste the content of public key. give some name as mySSH key. click on Add key.
9. Now click on repo you created in step # 1. Click on Clone and copy the SSH url. Do not select HTTPS Url. The url will be from your repo you created under Clone link. 

git clone <ssh_url_from_bitbucket_repo_you_created>



   11. Now after cloning, type ls -al command
12. It will show a folder with repo name..
13. navigate to repo folder by below command:
    cd mybitbucketrepo
14. use below command to create Java project using Maven. Maven is the build for creating and building java projects.
mvn archetype:generate -DgroupId=com.mkyong -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
15. type ls -al to see the new folder called MyWebApp
   16. type  below command to see the newly created project
git status





17. git add  *

18. Perform below command to commit the changes to local repository first.

git commit -m "my first project check-in to bitbucket"
19. Now perform below command to push from local repository to remote repository.

git push

Monday, 17 August 2020

How to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2

 

Please follow steps to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2. Jenkins is a java based application, so you need to install Java first. 

Java Setup on Ubuntu

sudo apt-get update

sudo apt update

Install Java Open JDK 21 package

sudo apt update

sudo apt install fontconfig openjdk-21-jre

java -version



Once install java, enter the below command


Verify Java Version

java -version

 

openjdk 21.0.8 2025-07-15

OpenJDK Runtime Environment (build 21.0.8+9-Debian-1)

OpenJDK 64-Bit Server VM (build 21.0.8+9-Debian-1, mixed mode, sharing)


Now lets do Jenkins installation

 

Installing Jenkins

Installing Jenkins on Ubuntu is relatively straightforward. We’ll enable the Jenkins APT repository, import the repository GPG key, and install the Jenkins package.

Import the GPG keys of the Jenkins repository using the following wget command:

sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt update

sudo apt install jenkins

Once the Jenkins repository is enabled, update the apt package list and install the latest version of Jenkins by typing:

sudo systemctl enable jenkins
sudo systemctl start jenkins

sudo systemctl status jenkins

You should see something like this:

●Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-11-13 16:19:01 +03; 4min 57s ago
...


Next Make Sure Port 8080 is Open

Go to your instance in AWS.... select Security Groups

Then click on the Security Group ID

Click on Edit Inbound Rules

Select Custom TCP Insert 8080 for Port range And set Source to 0.0.0.0/0

then Click Add rule

Access Jenkins in web browser

Now Go to AWS console.
  Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and Jenkins.

 

  Click on Action.

  Copy the value from step 4 that says --> Connect to your instance using its Public DNS


 

 

Now go to browser. enter public dns name or public IP address with port no 8080.This is how to select public DNS name:

 

http://EC2_public_dns_name:8080

 

Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)


Get the password from the below file

sudo cat /var/lib/jenkins/secrets/initialAdminPassword



Copy the password and paste in the browser

 

Click on install suggested plug-ins.


Also create user name and password.

enter everything as admin. at least user name as admin password as admin


Click on Save and Finish. Click on Start to Use.

 

Maven
sudo apt install maven -y


(To build Legacy maven apps)

sudo apt install fontconfig openjdk-21-jre



you can type mvn --version
you should see the below output.


 

Tomcat Installation

Tomcat is a web server or web container where java web application can be deployed by developers.

sudo apt-get update

sudo apt install fontconfig openjdk-21-jre


sudo apt-get install tomcat8 -y


 

sudo apt-get install tomcat8-docs tomcat8-examples tomcat8-admin -y


 

 

sudo cp -r /usr/share/tomcat8-admin/* /var/lib/tomcat8/webapps/ -v


 


Change port no from 8080 to 8090

sudo vi /var/lib/tomcat8/conf/server.xml


 

 

you need to scroll down by clicking down arrow button in this file change the port no from 8080 to 8090 at line starting with <Connector port="8080" protocol="HTTP/1.1"

 

setup an user in tomcat 

sudo vi /var/lib/tomcat8/conf/tomcat-users.xml

Scroll down all the way to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)

<role rolename="manager-script"/>

<user username="tomcat" password="password" roles="manager-script"/>

 


 

Add more memory to JVM

sudo vi /etc/default/tomcat8

Look for the line starting JAVA_OPTS and comment that line by adding #.

Add the below line:

JAVA_OPTS="-Djava.awt.headless=true -XX:+UseG1GC -Xms512m -Xmx1024m"

JAVA_HOME="/usr/lib/jvm/java-21-openjdk-amd64"

JRE_HOME="/usr/lib/jvm/java-21-openjdk-amd64"


 

sudo systemctl restart tomcat8

 

sudo systemctl status tomcat8


 

 

you may get message that says tomcat is active running.

press q for quitting from that window.

Now go to browser, copy public DNS
http://Ec2_public_dns_name:8090
  Note: Open port 8090 in AWS for this to work follow the steps on 
Next Make Sure Port 8080 is Open above

You should see a page that says.
It works!!!!



That's it. You have setup Jenkins and Tomcat successfully!!

 Watch installation videos Below

Part 1




Part 2

                                                                      




Part 3

IF YOU MISCONFIGURED YOUR TOMCAT USER PLEASE USE BELOW


<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="manager-script"/>

<user username="tomcat" password="password" roles="manager-script"/>
</tomcat-users>





Understanding Software Testing Using a Simple JSP Web App

  🎯 Lab Context (Very Important) This project is a basic Maven web application created for learning DevOps concepts. It displays a sim...