=============== Apache Maven =============== 1) What is Java 2) Java Projects 3) Java Project Execution Flow 4) What is Build Proces 5) What is Build Tool 6) Why we need build tools 7) Maven Introduction 8) Maven Setup (windows & linux) 9) Maven Dependencies 10) Maven Goals 11) Maven Repositories 12) Working with Maven ================ What is Java ? ================ => Java is a computer programming language => Developed by Sun Microsystems in 1991 => Using java we can build several types of projects 1) Stand-alone applications 2) Web applications => The application which is accessible only in one computer is called as stand-alone application. Ex: Calculator, Notepad++, Sublime text, VS Code IDE etc.. => The application which can be accessed by multiple users at a time is called as web application. Ex: Gmail, youtube, facebook, naukri, linkedin etc... ============================ Java Project Execution Flow ============================ 1) Developers will write source code (.java files) 2) Compile source code (java compiler) => It generate byte code (.class files) 3) Package .class files as jar/war for execution => stand-alone app will be packaged as jar file (java archieve) => web-app will be packaged as war file (web archieve) 4) If project is packaged as jar then we can execute jar file directley 5) If project is packaged as war then we need to deploy war file in server (Ex: tomcat) Note: To execute java applications we will perform Build + Deployment. ============================= Java Projects Build Process ============================= 1) Download required libraries / dependencies Ex : spring, hibernate, junit etc.. 2) Add libraries to build path 3) Compile the source code (.java to .class) 4) Execute Unit test cases (junit) 5) package project as jar / war file. => Earlier people used to perform this build process manually. => To avoid manual build process, build tools came into picture => Using build tools, we can automate project build process. ############# Maven is a build tool for java applications ########### ================= What is Maven ? ================= => Maven is a free and open source s/w => Developed by Apache org => Maven developed using java language => Maven is used as java projects build tool => It is used to automate java projects build process. =================== What maven can do =================== 1) Create project folder structure 2) Download required dependencies/libraries 3) Add libraries to build path 4) Compile project source code 5) Execute unit test cases 6) Package project as jar/war ========================= Maven Setup in Linux ========================= Step-1: Create Amazon linux vm and connect with that using ssh client Step-2: Install maven using package manager $ sudo yum install maven Step-3: Verify maven version $ mvn -version Note: To use maven java is required. When we install maven using package manager then it will install java also. =========================== Maven Setup in Windows =========================== @@@ Reference Video : https://www.youtube.com/watch?v=hV1OWzYpzxo 1) Download and Install Java 2) Set JAVA_HOME and Java Path 3) Verify Java Installation 4) Download Maven Software 5) Set MAVEN_HOME and Maven Path 6) Verify Maven Setup =================== Maven Terminology ================== => Archetype => Group ID => Artifact ID => Version => Packaging Type => Maven Dependencies => Maven Goals => Maven Repositories => Archetype represents type of the project quick-start : stand-alone app web-app : web application => groupId represents company name Ex: com.tcs, com.ibm, in.ashokit etc.. => ArtifactId represents project name Ex : sbi-netbannking-app, axis-loans-app, flipkart-app => Version represents project version number Ex: 0.0.1-SNAPSHOT, 1.0-RELEASE SNAPSHOT => Under development RELEASE => delivered to client => Packaging type represents packaging format Ex: jar, war => Maven dependencies nothing but libraries required for development Ex: spring, hibernate, junit, kafka, redis etc... => Maven goals are used to perform maven build process Ex: clean, compile, test, package, deploy => Maven Repositories are used to store maven dependencies/libraries/artifacts Ex : Central Repo, Remote Repo, Local Repo... ========================================= Creating Maven Stand-alone application ========================================= => Execute below command to create maven stand-alone application $ mvn archetype:generate -DgroupId=in.ashokit -DartifactId=sbi-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false => Check project directory structure using tree command $ sudo yum install tree $ tree sbi-app => Inside the project we can see 'src' folder and pom.xml file src : It is used to store project source code (.java files) main => java (business logics) test => java (unit test logics) pom.xml : Project Object Model (Maven configuration file) Note: Once project created, we can use maven goals to perform build process. ============= Maven Goals ============= => Maven Goals are used to perform Project Build Process $ mvn => We have several maven goals like below clean : To delete target directory compile : Compile source code of the project Note: It will convert .java files to .class files Note: It will generate target directory to store .class files test : To execute project unit test code test = compile + test package : To package our project as a jar / war file package = compile + test + package Ex : mvn clean package Note: jar / war will be stored in target directory. install : To publish our project artifact(jar/war) into maven repository install = compile + test + package + install ========================================= Creating Maven Web application ========================================= => Execute below command to create maven web application $ mvn archetype:generate -DgroupId=in.ashokit -DartifactId=my-web-app -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.4 -DinteractiveMode=false => Go inside project directory and execute maven goals $ cd $ mvn clean package => Once build got success we can see 'target' directory inside project directory. It contains byte code and our project artifact (war file). =================== Maven Dependencies =================== => Maven dependencies means libraries required for the project Ex: spring-core, junit, hibernate etc.. => We can find maven dependencies in www.mvnrepository.com org.springframework spring-core 6.1.7 => Add above dependency in project pom.xml file under section and execute maven goals. $ mvn clean package =================== Maven Repositories =================== Repositoriy : It is a place where maven dependencies will be stored => We have 3 types of repositories in maven 1) Local Repository 2) Cental Repository 3) Remote Repository => Local Repository will be created in our machine (.m2 folder) => Central Repository will be maintained by apache organization => Remote Repository will be maintained by our company to store shared libraries. Note: To setup remote repositories we will use Nexus / JFrog softwares. Note: Only First time maven will download dependencies from central / remote repository to local repository. => Maven project will take dependencies from local repository (.m2). ================== Maven - Summary ================== 1) What is Java 2) Java Projects Execution Flow 3) Stand-alone vs Web App 4) What is Build Process 5) Build Tools 6) What is Maven 7) What maven can do 8) Maven setup (windows & linux) 9) Maven Terminology 10) Maven Project Creation 11) Maven Dependencies 12) Maven Goals 13) Maven Repositories ================== Important Points ================== => Java Build Tools : Alternate for maven is 'Gradle' @@ Reference Video For Gradle : https://youtu.be/I84f9Q5bFBA?si=g8KcRXsPOtkvQohl => Dot Net Projects will use MSBuild. => Python : Build tool is not required