Build Tools- Maven-Day'26 & '27 &'28

Types of applications:
→ Stand alone application- The applications that are installed in our local systems eg: calender
→ Web application - * Static - content remains unchanged in this application, it is a presentation/GUI layer
* Dynamic -It is a 3-tier layer, presentation layer+application layer+data layer
presentation layer - html,css,javascript
application layer - python,java
data layer - sql(data is stored as table format) -oracle,mysql nosql(data stored as documents) - cassendra, mangodb,cashbase.
Mobile application-Android/IOS, Designed for smartphones and tablets, these apps are often downloaded from app stores. Examples include mobile games, banking apps, and navigation apps
Build Tool:
→ Build tool is a software utility, that will transform your code.
→ it is used to automate the process of transforming the source code into a deployable/excecutable artifact.eg: zip,zar,war,jar,tar.
these artifacts contains aplication code and its dependency.
→ Build tools are handling the task like
compile code→ convert source code into binary code.
Dependency Management → Download library from remote repository
Testing → Run unit test cases
Packaging → Create executable,deployable artifacts in the formats like .zar, .zip, .tar, .war
- > .zar file contains java files
Build tools and the languages that are used by them:
Java - mavon, ant, gradle
node JS - npm, gulp, yarn
python - pip, pybuilder, setuptools
go lang - go build
.net - MSbuild, nant
ruby - composer
Maven:
→ Maven is a java based build tool
→ Maven is a build and dependency management tool for java based projects.
→ It has pem.xml file
→ Apache software foundation developed this build tool, he is the vendor
→ Maven is a open-source and free build tool
→ Maven is platform(os) independent→ we can install maven in any os
→ Maven is not an executable software (.exe/.msi)
it is distributed/given in zar/zip file format, we have to extract it.
Maven Requirements:
.jar(java archive)→ contains .class files(compiled java code)
.war(web archive)→ .jar files+web content(html/css/javascript)
.ear(enterprise archive)→ .jar+.war+ear modules
→ To deploy the .jar application
java -jar <jar file name>
→ war files can be deployable on software like tomcat, jetty, glashfish
→ear files can be deployable on software like Jboss/widfly, weblogic, web sphere.
JRE(Java Run-time Environment)- To run the java application, used to execute the compiled code.
JDK(Java Development Kit)-It compiles the code, it is a compiler with JRE
JDK internally contains JRE.
JVM(java virtual machine)- It is the core component of JRE.
responsible for executing the bite code(compiled code).
Maven system requirements:
→ JDK 1.8 or above
→ OS - It supports any OS
→ The current stable version of maven is 3.9.10 requires JDK 8+
→JAVA 1.8,1.9
java 11, java 17,java 18
→pom.xml- build file/script
(project object model)
→Any pom file starts with <project> tag and ends with </project> tag
<project>
<group ID></group ID>
<artifact ID></artifact ID>
<version></version>
</project>
group Id -project group name
artifact id - name of the project
version - release version or snapchat version(on going project)
→ Maven repository:
It is a centralized storage for storing and retrieving project dependencies(libraries, plugins, other artifacts).
It is divided into
→ local repository- default location: ~/.m2/repository
It is basically like a directory in our local system, where maven can download and maintain the dependencies , plugins, libraries locally.
→ central repository- public repo managed by Maven community
→ remote repository - an customer/third party repository
The repository created within the organisation to share and download the libraries, artifacts within organisation.
It is configured in pom.xml or in settings.xml
→local→remote→central
→ If we want to change the local repo path(location), we can do that, that can be done in settings.xml
conf→settings.xml
If the dependencies and plugins can present in local repository, we can’t go for central and remote repository
If the dependencies and plugins are not there in local repository then check in remote and in central.
Maven life cycle:
Maven life cycle is used to build the maven project
Maven life cycle phases:
→ Maven will build project (application ) using pre-defined life cycle, which contains phases
There are 3 standard life cycles in maven:
→ Default life-cycle
→ clean
→ site
→site- This is used to generate documentation about the project.
→Default life-cycle- this is the core life-cycle, used for building the project and deploy the project.
It has so many phases:
→ validate- validate if any systematic errors in the project
→ compile- convert .java files into .class files
→ test- run-time test cases
→ package- once the code is compiled and tested,we need to create a package to deploy the code in somewhere → target/app.jar
→ verify- To check the code quality
→ Install- Deploy the code to local repo
→ deploy- push the final code from local repo to remote repo
mvn package→ It is going to create only package, it does not add the package to the local repository
mvn Install→ It is going to create package, if it is not created and add the package to the maven local repository
→clean- This is responsible for removing the previously build files, artifacts.
mvn clean→it is going to remove the target folder
while creating and running the packages, if we want to skip the test cases we can by
mvn clean package -DskipTests ( it runs the test cases but won’t compile it)
mvn clean package -Dmaven .test .skip=true (it won’t compile and run the test cases)
mvn package → validate, compile, test, package
mvn test → validate, compile, test
mvn install → validate, compile, test, package, verify, install
mvn clean # Remove previous builds
mvn compile # Compile code
mvn test # Run unit tests
mvn package # Generate JAR/WAR/EAR
mvn install # Store in local repository
mvn deploy # Upload to remote repo
mvn clean package # Run multiple goals
Java Installation:
→create server(ec2-instance) and ssh the server
→switch to root user
sudo su -
→yum install wget -y
→wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
to download the java, but it is downloaded in tar format
→tar -xzf openjdk-11.0.2_linux-x64_bin.tar.gz
To extract the tar file
→ mv jdk-11.0.2 /opt/java-11
To move the downloaded file to opt/java-11
→ rm openjdk-11.0.2_linux-x64_bin.tar.gz # Remove Once Extracted
The java is installed in the opt folder
→ls /opt/java-11
In bin folder we have all the java related files.
→ls /opt/java-11/bin/
At default the java is installed in here, we have to set the path at user level and system level.
user level: only the current user can use this software.
system level: It is available for any one (user/server)
For appending the path:
user level - The path can be set in root user
system level - The path can be set in opt/profile
To set the path in user level:
echo 'export JAVA_HOME=/opt/java-11' >> ~/.bash_profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> ~/.bash_profile
source ~/.bash_profile
→ java -version
to check the java is installed or not
To set the path in system level:
sudo tee /etc/profile.d/java.sh <<EOF
export JAVA_HOME=/opt/java-11 export PATH=\$JAVA_HOME/bin:\$PATH EOF
source /etc/profile.d/java.sh
→we can directly execute the above commands or in the etc/profile file we can add those echo statements in the file.
vi /etc/profile
→or we can create the separate file in the name of java.sh in the profile folder and add the echo statements in the file.
→ls /etc/profile.d/
to check the java files within the profile folder
→exit from the root user, as the path can be setted in root user only, If we want to set the path in user and system level
In the same way that we have done in the root user repeat the same steps to create the path in both user and system level
At the end execute the below command to see the java is installed or not
→java -version
Maven Installation:
switch to the root user
sudo su -
change the directory to opt as the maven installation can be done in there
→ cd /opt/
→wget https://dlcdn.apache.org/maven/maven-3/3.9.10/binaries/apache-maven-3.9.10-bin.zip # maven is downloaded in zip format
unzip apache-maven-3.9.10-bin.zip #to unzip the zip file
rm apache-maven-3.9.10-bin.zip # Remove Once it's Unzipped.
→ ls /opt/apache-maven-3.9.10/
→ls /opt/apache-maven-3.9.10/bin/
the maven related files are all in the bin folder
Now we have to add the bin files to the path(user and system)
system level:
echo 'export M2_HOME=/opt/apache-maven-3.9.10' >> ~/.bash_profile
echo 'export PATH=$PATH:$M2_HOME/bin' >> ~/.bash_profile
source ~/.bash_profile
system level:
sudo tee /etc/profile.d/mvn.sh <<EOF
export M2_HOME=/opt/apache-maven-3.9.10 export PATH=$PATH:$M2_HOME/bin EOF
source /etc/profile.d/mvn.sh
→ mvn --version
to check the maven is installed or not
Then exit from the root user and define the path to the user and system level in the same way that we did in the root user.
Subscribe to my newsletter
Read articles from Sandhya Kalikiri directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
