Find the best tutors and institutes for DevOps Training

Find Best DevOps Training

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

DevOps Maven Lession

Vinod M
16/03/2019 0 0

            ################### Maven ####################
Maven Index:
1. Introduction To Maven
2. Installation
3. Architecture
4. Default lifecycle
5. Directory standards
6. GAV
7. Test project
8. one by one goals executions
9. jar, war files
10. Plugins
11. Maven Profile
12. Dependencies

Build Tools/Build Automation/Management/Process

--> Build Management: is a process that we compile and assemble all the source code(written by developers) into object files.
        ex: 100 files
            100 object files(.class files)

>>Ant--> Java(Apache Foundation)
>>Gradle--> Alternative for Maven
>>Maven--> latest and updated one

Ant and Maven:
>> actions are defined in ant(so much of scripting)  >> in maven say what to do not how to do
>> sequences are defined in ant              >> how to build is defined in maven (life cycle)
>> no default directory layout                >> it fallows standard directory structure
>> ant fallows you                           >> you need to fallow maven
>> librarys are part of source code                  >> librarys are not part of source code
    (difficult to maintain)

>> Compiling Source Code               
>> Packing Biniries/artifacts
>> running Automated tests                         
>> Deploying to production system
>> Creating Documentation    

--> diff with other tools
    >> open source
    >> it is not only build tool and also project management tool
    >> it has set of standards and object modules,so no need to instruct     
    >> default project lifecycle
    >> dependency management

Environment Variables
    # user
    # system ($PATH)
echo $HOME
echo $SHELL

-->if we want to use variables globals(in all shel windows)then
export name=vinodh (in bashrc file)

Maven Installation in Windows:  
--> install java
--> Download java JDK & JRE (or)
--> Go to-->mycomputer-->properties-->Advanced system settings-->environment variables-->system variables
--> path    ;C:\Program Files\Java\jdk1.8.0_131\bin;C:\Program Files\Java\jre1.8.0_131\bin  ---> to system variables PATH by seperater ;
            JAVA_HOME should point to JDK(without bin)

--> install Maven
Go to this website to downloab(Zip)-->
    D:\Apache_Maven ---> MAVEN_HOME in system variables
    path--> ;D:\Apache_Maven\bin

Maven Installation in Linux::
 Step1. yum install -y java-1.8.0-openjdk-devel
 Step2. java -version
 Step3. cd /usr/local/src
 Step4. wget
 Step5. tar -xf apache-maven-3.5.4-bin.tar.gz
 Step6. mv apache-maven-3.5.4/ apache-maven/
 Step7. cd /etc/profile.d/
 Step8. vim
             >> export M2_HOME=/usr/local/src/apache-maven
             >> export PATH=${M2_HOME}/bin:${PATH}
 Step9. chmod +x
 Step10. source /etc/profile.d/ (for loading the configuration)
 Step11. mvn --version
           o/p:- Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T19:33:14+01:00)
               Maven home: /usr/local/src/apache-maven
               Java version: 9.0.4, vendor: Oracle Corporation, runtime: /opt/java/jdk-9.0.4
               Default locale: en_US, platform encoding: UTF-8
               OS name: "linux", version: "4.17.6-1.el7.elrepo.x86_64", arch: "amd64", family: "unix"

vi /etc/profile
vi /etc/bashrc

verify whether java/maven is installed or not in CMD prompt by typing below commands
Javac --> compiler
java -->keyword
java -version --> runtime environment
mvn --version

How Maven works:(Architecture)
                    Build System
                      |                 |          
                          |    POM.XML    (conf file)  |       HTTP            
     local repository <<------|    (goals)             |--------------->> Remote Repository     
                  |                 |            (maintained by Maven opensource Community)
                  |        Maven         |
--> it works as a GOALS, internally goals as plugins/jar files which has the future of when and what it has to do
    eg:- maven do testing; --->>  then it call plugin to do testing
Default lifecycle:   
    1. generate-source/resource (.java files)
    2. compile -->all .java files into .class files
    3. test  ---> Unit test (a peace of code)
    4. package --> deliveriable or executable or Artifacts(which contains all)
    5. integration-test(pre and post)
    6. install                            
    7. deploy
    --> clean :- it deletes all runtime files
    --> site : - documentation(99% we will not use, very rare cases like audits...)

Example Maven Goles:
To invoke a Maven build you set a lifecycle “goal”
mvn install
note:- mvn -f pom.xml <goal>
Invokes generate and compile, test, package, integration-test, install

mvn clean
Invokes just clean

mvn clean compile
Clean old builds and execute generate, compile

mvn compile install
Invokes generate, compile, test, integration-test, package, install

mvn test clean
Invokes generate, compile, test then clean

diff source and binary code
    1. source code which we can customize
    2. binary code is a product which we can buy directly

Standard Directory Layout:
>> if you want to work with maven project, then we need to follow the maven standard directory structure through which maven will work.
main-->actual source code, lib files,additinal info, property files....etc
test --> unit testing files

once you start compile, maven will go to src/main folder to compile (what are the files you gave over there)

--> how maven identify which plugin or project to select when we instruct a goal. (G.A.V)
    G(groupid) -- string rep company name / group name / business org on which u doing project.
    A(artifactid) -- string rep product or deliverable(final output of your product)
    V(versionid) -- Major.Minar.Patch/Maintanance( add SNAPSHOT to identify in development)
    packaging -- build type identified using the packaging element
    eg : - pom ,jar(default),war,ear
 note: - by keeping pom in packaging it acts as a parent pom of all modules
mvn archetype:generate

--> jar - java archive(default package maven uses which contains group of .class files, so we group this to get a particular behaviour)
--> war - web archive - contain group of jar + config + xml (for web based projects)
--> ear - enterprice application

Note:- How maven knows,where java files,what it has to do,where to keep files and fetch files....etc this all done by below two files
  to run maven default life cycle
1)dir structure
2) pom.xml file in dir

--> remote maven repository located in -
--> local repo located in c:/user/vinodh --> .M2 --> Repository

POM:(conf file)
Project object model is fundamental unit of work in maven,POM is an xml file that contains information about project and configuration
details used by maven to build project. pom conf file contains below list.
--> atlest one pom.xml file should be there in product/project
    @ Describe a project
    @ name and Version, Artifact type,source code location, Dependencies
    @ Plugins
    @ Profiles(Alternate build configuration)    
    @ it uses XML by default

if we want instruct anything to maven through goals we will do, goals internally have plugins/jar files.
    1. Build Plugins : we will use this for entire life cycle
    2. Reporting Plugins : create documentation of product (for site phase only)

      1. GAV - what is plugin (identify the plugin)
      2. when you have to run the plugin
      3. how to use plugin(like conn DB, insall, disconnect...etc)
      4. what exactly to do
      -- plugin 2 infomation
                      <echo>hallo world=============</echo>



Note:- what plugin we selecting, what syntax(GAV) of plugin, And how to call....    
--> maven ant plugin, maven exec plugin....

how to call a individual plugin:
mvn <GOAL>
mvn exec:exec
mvn exec:java
--> mvn <plugin>:<goal> ---> we can call plugin directly without phase/goal

  1. it is under development build (or) dev copy which is not yet finalized(only we will change before releasing client)
  2. other projects are depend on this, if i rebuild the jar name other proj looking for this

Maven Profile:
def:- buid profile is a set of configurationns values which can be used to set or override dafault values of maven build.
using a build profile, you can customize buid for different environments such as production v/s developmennt.

--> some times you want to execute only default plugins not all mentioned in build, at that time we can use.
    mvn clean (default)
    mvn -Pdemo  specify goal(all plugins)


--> profile can activate many types like env, os, settings.xml in repo...etc

Multy-Module Projects:

--> if you have 1000 files in project it is diffcult to maintain, so make modules/components like add, sub, dev of calculater project and copy src,pom file in each.
 note: - by keeping pom in packaging it acts as a parent pom of all modules (parent and child relationship)     demo (parent) > add, sub (child)

Maven has 1st class multi-module support
Each maven project creates 1 primary artifact
A parent pom is used to group modules

issues -1:
 >> executing all modules every time

parent and child relationship, by keeping 'pom' file in "packaging"


>> Dependencies
-->adding add.jar to subtract for dependency..

      <version>1.0 SNAPSHORT</version>

<dependencies>                |
    <dependency>            |
      <groupId>junit</groupId>        |
      <artifactId>junit</artifactId>    |------------>> junit plugin is default plugin for performing test phase
      <version>3.8.1</version>        |
      <scope>test</scope>        |
    </dependency>            |
  </dependencies>            |

by using "install" phase in add module, then add.jar will move to local repo

mvn install--> copying jar file form local project folder to local repository

giving parent gav in child ==>>complete parent and child rel

Dependencys how maven know:
--> if sub is depend on add file then we need to keep add file GAV into sub file dependency.
--> error :- not able to find add file, then install add file from local project folder to local repository
              mvn install


0 Dislike
Follow 1

Please Enter a comment


Other Lessons for You

How to install Apache HTTP in Linux OS
sudo bash // for becoming super user // now left hand side you can see root yum update // for updates yum install httpd // for installing httpd software service httpd start // for starting httpd software Once...

VSS Sasidhar | 29/04/2020

0 0

Top 6 Technology Trends for 2020
Technology has been evolving at a pace that the annual predictions about trends may seem to be outdated before they go live as a published blog post or article. The technology when evolves...

Use Nexus as Docker Registry
There are different tools provides docker registry, and in this tutorial, we want to use Sonatype Nexus Repository Manager as our docker registry, and we will upload our images in there. I am using the...

Raghu K | 28/03/2018

0 0

DevOps Git
Removing a file from git staging (index) area. Assume git add sample file => for adding the file to git staging area. Check the git status command Use git rm for removing the content from working...

DevOps Training Course
DevOps Syllabus: DevOps Essentials: What is DevOps? Why DevOps? Evolution of Software Methodologies Dev Challenges v/s DevOps Solution Ops Challenges v/s DevOps Solution Stages Of DevOps Lifecycle...

Looking for DevOps Training Classes?

Find best tutors for DevOps Training Classes by posting a requirement.

  • Post a learning requirement
  • Get customized responses
  • Compare and select the best

Looking for DevOps Training Classes?

Find best DevOps Training Classes in your locality on UrbanPro

Post your learning requirement is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on, to fulfill their learning requirements across 1,000+ categories. Using, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more