open your browser and come to this link.
GitHub.com slash coder slash profile hyphen project.
So this is our source code.
And you see there is a file Pom.xml.
That's the build file for Maven.
As soon as you see Pom.xml, that means definitely it's a maven project.
Let's open this file.
So this file, as it says, it's in XML format.
And when developers start writing the code, they're going to initiate the Maven project, which will
create a sample pom.xml file for them and then they will make changes to that.
They will build it, test it.
If everything is good, they are going to push the source code into repositories like GitHub.
So as a DevOps you should be able to read this file and when the requirement comes, should be able
to also edit.
Mostly you won't need to edit, but there are certain situations, certain times where you need to make
changes.
Don't worry, you don't need to get into too much into XML as well.
Just understand this opening and closing.
So for example, this is the opening group ID, and then there is the data.
Or you can say value and then this is the closing.
Like artifact ID.
The profile.
That's the value packaging.
The value is var think of this as normal variables version v2.
So when we build our artifact we see V profile hyphen v2 dot var.
So those values are coming from here.
If you come down, you have properties.
These are the variables that will be used later in this Pom.xml file itself.
For example, MySQL Connector version 8.0.32.
So we upgraded from 5 to 8 MySQL and later we might upgrade more based on the demand situation.
Okay.
If you come down we have dependencies.
These are the, you can say the maven dependency.
When you build the project with Maven first Maven will look for the dependency and it is going to download
this dependencies from the Maven website or Maven repository which is publicly available.
So these dependencies will be mentioned by the developers based on what they are creating.
They are going to use those kinds of dependencies.
Spring for spring framework.
And here you have the version.
So this is the value you see there.
Dollar in the curly brace.
You have spring dot version.
Now this should be defined here.
Spring dot version.
Its value is 4.2.0.
So like that there are all these dependencies.
This will be general structure of mentioning the dependency.
You have group ID, you have artifact ID and you have version.
So majorly.
You see, this file contains the dependency.
And you can also find here build plugins.
Jacoco.
Unit Testing Framework Plugin.
So in order to understand this much better.
We will do some hands on.
We'll launch an EC2 instance, we'll fetch the source code and we'll build it with Maven and we'll see
a few other options with Maven commands.
So I'm on my EC2 console.
I'm going to launch an instance of Ubuntu.
Might simply call it as build server.
Open to 22 should be good.
T2 Micro is fine.
Let's create a key pair called it as just build key.
I'm really not doing anything with the security group, just keeping it anywhere and simply launch instance.
Okay.
It's in a running state.
I'm going to switch to it.
Copy the public IP.
So open the terminal.
My sister Tiffany downloads build key open to add the rate and the IP address.
Okay.
So I'm going to clear the screen and first run sudo apt update.
Okay, so we need to fetch the source code and build it using Maven.
So we will need git to clone the source code and git will be anyways installed in ubuntu machine so
we don't need to install git.
So we have to install maven.
But maven has a dependency of JDK Java development kit.
So there is also a Java runtime environment, but that is just to run Java softwares.
If you are doing development or you're building like we're using Maven, we will need JDK, so we have
to search.
I'm going to say sudo apt.
Search JDK.
Let's search for JDK.
Now which version of JDK to use depends on your project.
Our profile project works on JDK eight and it works on JDK 11 also, so we can go with JDK 11.
So this is the package open JDK 11 hyphen JDK.
Let's install that sudo apt.
Install.
Hyphen y.
Okay.
So JDK is installed now in ubuntu.
That's the package name.
If you are using a centers or any RPM based OS like Amazon linux, you have to again search m search
JDK and the package name will be different.
The JDK 11 package name will not be the same as the Ubuntu.
It might be different, so you have to search through the repositories apt search.
Yum search.
And then find the package name and install it.
So we need JDK 11 or JDK eight.
Also works, as I told you.
Now the next thing we need is Maven.
Let's first check the Java version.
Hive Java hyphen version.
Just one single hyphen.
So you see open JDK version 11.
Now we will install maven.
APT install maven.
Okay.
I have to give to their.
Okay.
It's installed.
Let me check.
MVN hyphen version.
So the command is mvn.
The package name is Maven, but command is mvn.
So you see, that's the Maven version.
It is using Apache Maven and Java version.
It is using 11 now by default.
Also Maven three from 3.5, 3.6 onwards.
By default it needs Java 11.
Even if you install different versions of Java and or if you don't have any Java JDK installed, you
say APT install Maven.
It is going to install Java version 11 as a dependency.
But anyways, you already took care of that.
We installed first and then Maven.
So see this is the package manager way of installing Maven.
But there is if you want a different version of Maven, like maybe 3.9 or something like that, then
you have to download its tarball, extract it and then use it.
So if you're looking for different version of Maven, just Google Maven Archive.
And this is the link.
For Maven three See different versions here, different folders.
Let's go with 3.9.3.
Not one or anything that is in the three version you can take binaries.
And this is the tarball I was talking about.
So bin dot tar dot get this one.
So just right click to it and copy link address.
Let's go to the instance.
We'll say wget.
If WJ is not installed, you have to install it.
Okay.
It is extracted now.
Download it.
Let's extract it.
Tar Xvf Apache Maven.
Let me clear the screen.
You should see this folder.
Now we will move this folder, but let me show you first.
Apache Maven 3.9.3 and it contains a bin folder in the bin folder.
You should have the mvn.
Okay, now from here itself.
But if we give it like this Apache maven.
Bin.
MVN and we say hyphen version.
See 3.9.3 and see using Java 11.
But you should never keep it at such places.
We will move it sudo mv Apache maven 3.9.3 to opt.
Or other places.
Also, you can move.
And let's do now slash opt Apache maven bin mvn hyphen version.
So default maven, you can just run command.
But if it's a different version of Maven, if you're maintaining multiple merged versions of Maven,
this is how you should invoke it by giving its absolute path.
Okay, so we have all the dependencies.
Now let's clone the source code.
Git clone.
Come to our repository.
Dropdown on the code.
Copy the link.
Let's paste it here.
Okay, that's there.
Let's do profile project.
So let's run different phases of Maven.
From here you have to say make sure you are in the folder where you have Pom.xml file because Maven
will need that.
So, Maven, let's do Validate.
Okay, so it just says build success because validate doesn't do really anything, but we can run the
phase and test.
Okay.
So now it is going to also require some dependency, which it is going to download.
You see that downloading from Maven Archives.
Maven Repository.
It's downloading the dependency to run the test.
So this is a little faster on EC2 instance.
If it's on a VM, it takes our internet and it takes time.
Internet is very fast.
Okay.
So it's running the test now.
Okay.
And it says build success.
If you do, you should find a folder called Target.
And in this target folder, you should find.
The reports generated by the test case.
Now you have a target folder and if you want, you can do MVN clean, you can just remove the target
folder or you can do mvn clean, which will.
Remove all those things.
Let's.
See target folder is gone or you can just run MVN clean and a face like for example, install now install
we know executes all the previous phases before this right?
Every phase execute all its previous phase.
So if we run and install it is going to execute all the phases.
And if there is already the data, you want to remove that data and then run, you can say MVN clean
install.
Okay.
It says completed.
You do.
LZ, you should see the target folder and you see LZ Target.
And now you should see everything, including the artifact also.
Now this is the artifact, the archive, the name.
Check that in the Pom.xml file we have the artifact profile version is V2 and packaging as var.
So taking those names, it has archived the artifact with this name.
This basically is an archive of this folder.
This you can directly also deploy to the servers this folder, but if it's a var file we deploy the
var file or jar or whatever the destination is target based on that, it is going to archive what developer
has mentioned.
Now also look at this thing.
When it is downloading the dependencies, it is going to store it at this location slash home slash
ubuntu dot m2.
Let me clear the screen.
Ellis slash home slash ubuntu.
I mean your user what your user's home directory inside that you will have M2 and inside that you have
repository and all these are the dependencies.
Now if we run mvn install.
All right.
So these dependencies already exist over there, so it is not going to download it again until unless
there is a change in your pom.xml file dependencies, it is not going to download it again.
It's going to use from your system.
You see, it is not downloading anything.
And says build success.
But if we want, we can clean that also, right?
Hyphen rf I'll say slash home Ubuntu dot m2 repository star.
So remove everything from the repository folder and now if I run mvn install or clean install clean
will just remove the target folder.
Anyways.
I'll just run install first.
So now you will see it will again start downloading.
It will check the pom.xml file.
If the dependencies exist, it is not going to download.
If it does not exist, it is going to download.
Just keep this in mind.
Whatever user is running the Maven command right now, Ubuntu user is running the Maven Command, so
Ubuntu user's home directory will store the dependency by default.
If the user is Jenkins then slash home slash Jenkins dot m2.
So whatever username you have.
And that user's home directory, the dependencies will be stored.
Okay, so our project works with the newer version of Maven also.
But before that, let's remove the old dependencies.
Not old.
It will use the same one also and we'll say mvn clean.
So remove the dependency repository.
And remove the target folder and then we'll see.
Opt Apache Maven.
Bin.
Right.
And then mvn.
Install.
So now building the artifacts with Maven version 3.9.
And whenever you're switching versions like this, it's recommended you remove the old dependencies.
Sometimes there are conflicts, sometimes it fails.
So remove the old dependencies and remove the target folder and then use your different version of Maven.
Okay, let's make some changes to pom.xml file.
Like we will change the version from v2 to, let's say V3.
V3.
C1 Quit.
And we'll see.
MVN clean install.
Wait.
First let me show you target.
So let's v profile v2 dot var and I'm going to say MVN clean install.
Okay, that is completed.
Let's look at the target folder.
See that we profile V3 dot dot var.
Right.
So like that, sometimes you might need to make changes to the pom.xml file.
Sometimes you need to change the versions of the dependencies, but very rarely the developers will
mostly define the dependencies and their version, but you should have at least some idea of how to
make the changes and then build it.
So this is this is really simple, right?
And you can test the build process in your local machine.
Also, you can open PowerShell or terminal install JDK 11 and Maven so Windows User can use Cocoa Command.
We have already installed Chocolatey and Brew on Mac and we had installed Java JDK 11 and Maven in the
Prerequisites lecture.
So you can clone the source code in your local machine and build it by using Maven test that.
Take it as an assignment.
Just make sure first you check the version of Java.
It should be Java 11 and then Maven should be using Java 11.
You have you can check Maven Hyphen version command.
You can see what Java version Maven is using.
And it was not really necessary to launch the EC2 instance.
We could have done it on a local machine or there is also AWS cloud shell from here.
Also, we can run the Maven commands, we can clone the source code, but remember the JDK package names
will be different if you open AWS Cloud Shell.
Let me open it full screen.
Okay, so this is the cloud shell, right?
Uh, cat EDC os release.
So check it's built on Amazon Linux two.
So we have to use, um, the package manager.
Right?
So we can say sudo yum search JDK.
Search for JDK.
First, you can go with JDK 1.8 also, or I think that's the only one.
So let's go with 1.8.
If you see JDK 11, you can go with that one also.
I'm going to say sudo yum install.
JDK version hyphen VI.
As I told you, our project runs on JDK 11 and eight.
Also 1.8 basically means JDK eight.
So it will work.
We have to install after this maven, clone the source code and build the artifact.
Okay.
Then we're going to say sudo apt install.
Maven Hyphen VI.
Sorry.
Not apt.
It's yum.
Now there is also a JDK from Amazon called as Corretto corretto and you can search it like this.
Sudo yum search.
Java.
Our corretto.
I think we should find it.
Okay, There you see that Java 11 Amazon Corretto.
So we could have installed this one also.
But anyways, both works, no problem.
So you can see this is the JDK 11 from Amazon.
So Amazon created this JDK level.
Okay.
Anyways, let's run mvn hyphen version.
All right, so Maven version three and Java, it is using 1.8.
Okay, now let's clone the source code.
And clear the screen.
Git clone.
And then CD into that repository and we can run mvn install.
Okay, that's there.
Now, if you want, you can copy this also to S3 Bucket.
AWS S3.
If you don't have S3 Bucket, you can see AWS, S3 create a bucket.
So I'm just saying, AWS S3, S3, Colon slash slash maven, Hyphen Arts.
And then I'm going to say AWS S3, CP Target.
Target slash profile hyphen v2 dot var.
And S3 Colon slash slash Maven Hyphen Arts.
See that is way faster than copying from our local machine.
Okay, so all these fun things benefits you get from AWS Cloudshell.
Anyways, our focus was on Maven, but you got the point.
Now you can build your artifact, you can fetch your source source code and build the artifact anywhere
you want.
You just need to install the right dependency based on the right operating system.
So that is all in this lecture.
Terminate the EC2 instance that we had created previously and don't stress too much about Maven.