SlideShare uma empresa Scribd logo
1 de 33
fli@telenav.cn MAVEN
Preface Do you ever begin a new project from scratch? What’s you do before your first line code? Do you maintain the build script in your Team? Which kinds of tool do you use (make, ant, ivy,  maven, mercury,…)
Outline Key concept Basic Usage Demo 20% usage Ant vs Maven
Key concept
Plugin : (task in Ant) Maven is a plugin execution framework.  Adding functionality to Maven is done through the plugin mechanism. (all work is done by plugins) Similar to Ant Task/Ant Target(not exactly) from the user view  A collection of goals (tasks)
Plugin
Plugin Ant Maven <targetname="compile"depends="init"description="compile the source "> <!-- Compile the java code from ${src} into ${build} --> <javacsrcdir="${src}"destdir="${build}"source="1.6"target="1.6"/> </target> <build> … <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> … </build>
Lifecycle : the plugin-goal (task) execution sequence <projectname="MyProject"default="dist"basedir="."> <description>         simple example build file </description> <!-- set global properties for this build --> <propertyname="src"location="src"/> <propertyname="build"location="build"/> <propertyname="dist"location="dist"/> <targetname="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdirdir="${build}"/> </target> <targetname="compile"depends="init"description="compile the source "> <!-- Compile the java code from ${src} into ${build} --> <javacsrcdir="${src}"destdir="${build}"/> </target> <targetname="dist"depends="compile"description="generate the distribution"> <!-- Create the distribution directory --> <mkdirdir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jarjarfile="${dist}/lib/MyProject-${DSTAMP}.jar"basedir="${build}"/> </target> <targetname="clean"description="clean up"> <!-- Delete the ${build} and ${dist} directory trees --> <deletedir="${build}"/> <deletedir="${dist}"/> </target> </project>
Lifecycle : the plugin-goal (task) execution sequence goals( pluginname:goalname) default
Lifecycle A lifecycle is made up of phases These build phases are executed sequentially (including all of the prior steps) A Build phase is made up of goals A goal represents a specific task, minimum execute unit (task) A goal is bound to zero (direct invocation) or more build phases mvn jar:jar  ----------- plugin-goal prefix-name (mvngroupID:artifactID:version:goal) mvn package ----------- lifecycle phase name ,would execute jar:jar, because jar:jar is one contained goal in package phase
Lifecycle: build-in lifecycle default clean site
Lifecycle: build-in binding goals
Lifecycle : adding more goals by plugin Plugin: are artifacts that provide goals (tasks) to Maven   <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <configuration> <outputDirectory>doc</outputDirectory> <show>public</show> <nohelp>true</nohelp> <windowtitle>TNT-CAL API doc</windowtitle> <doctitle>TNT-CAL API doc</doctitle> <maxmemory>256m</maxmemory> <sourcepath>src/main/java</sourcepath> <charset>utf8</charset> <locale>en_us</locale> </configuration> <executions> <execution> <id>api-doc</id> <phase>prepare-package</phase> <goals> <goal>javadoc</goal> </goals> </execution> </executions> </plugin>
Dependency: no flying jars No need download dependency lib one by one, declare it, Maven download for you Shrink the project size in svn <dependencies> … <dependency> <groupId>com.telenav</groupId> <artifactId>ace-client</artifactId> <version>1.0.0.15</version> <classifier>release</classifier> <type>jar</type> </dependency> <dependency> <groupId>com.telenav</groupId> <artifactId>kernel</artifactId> <version>a1.3-b101</version> <type>jar</type> </dependency> … </dependencies>
Dependency: transitive Compile ok, runtime ‘NoClassDefFoundError’ ---- Need transitive jar Transitive (Chain) A -> B -> C Transitive config Shortest path A -> B -> C -> D 2.0 and A -> E -> D 1.0 Dependency scope Dependency management : inheritance; import
Dependency: transitive Dependency scope (IVY configuration map) C (compile) B (compile) A D (runtime) E (test) compile test runtime
Profile Different build configuration for different target environments Different OS Different deploy environment Activation  -P CLI option Based on environment variables… Maven will execute the steps in the profile in addition to the normal steps
Profile <profiles> <profile> <id>cn-dev</id> <activation> <property> <name>target</name> <value>cn-dev</value> </property> </activation> <properties> <encoding>gb2312</encoding> </properties> </profile> <profile> <id>us-deploy</id> <activation> <property> <name>target</name> <value>us-deploy</value> </property> </activation> 			<properties> 				<skipTests>true</skipTests> 			</properties> </profile> </profiles>
Basic Usage
Create a project Create mvn archetype:generate –DarchetypeArtifactId=maven-archetype-quickstart –DgroupId=com.telenav –DartificatId=rgc Project layout http://stackoverflow.com/questions/4182794/in-maven-what-is-the-difference-between-main-resources-and-main-config
Demo : Hello World Build Package Test Report Install/Deploy/Release mvn install: to local repository mvndeploy: to remote (release) repository mvn release: deploy and tag the source code by scm.
20% usage Eclipse plugin Properties Repository Inheritance & Multiply-module Write a maven-plugin
Eclipse-plugin m2eclipse http://m2eclipse.sonatype.org/installing-m2eclipse.html Add-dependency (search) Add-plugin
Properties Build in properties ${basedir} represents the directory containing pom.xml ${project.basedir} represents the directory containing pom.xml Project properties <project><version>1.0</version></project> is accessible via ${project.version}. Environment variables ${env.PATH} Java System Properties ${file.separator} User-defined Properties Plugin property expression: ${maven.compiler.target} Setting property
Repository Add repository (Telenav) <repositories>  <repository> 			<id>telenav</id> 			<url>http://tar1.telenav.com:8080/repository</url> 			<releases> 				<enabled>true</enabled> 			</releases> 			<snapshots> 				<enabled>false</enabled> 			</snapshots> 		</repository>  </repositories> mvn install:install-file -Dfile=<path-to-file>  -DgroupId=<group-id>  -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
Repository (Deploy) Distribution artifacts to release repository <distributionManagement>  <repository> <id>nexus</id> 	<url>http://192.168.109.118:8080/nexus/content/repositories/releases/</url>  </repository>   <snapshotRepository> 	<id>nexus</id> 	<url>http://192.168.109.118:8080/nexus/content/repositories/snapshots/</url> 	<uniqueVersion>false</uniqueVersion>   </snapshotRepository> </disctributionmanagement> // $M2_HOME/conf/settings.xml // scp password or nexus deploy password or tomcat manage password, dependent on distribute url <servers>	<server>		<id>maven2-snapshot-repository</id>		<username>repoman</username>		<password>mypassword</password>	</server><servers>
Repository (Release) <build>   <plugins>    <plugin>      <artifactId>maven-release-plugin</artifactId>      <version>2.0-beta-9</version>      <configuration>      <tagBase>            http://svn.telenav.com/tnt/Backend/tntcal/tags/tntcal-core </tagBase>      </configuration>    </plugin>   </plugins> </build> <scm>     <developerConnection>scm:svn:http://svn.telenav.com/tnt/Backend/tntcal/trunk</developerConnection> </scm>
Repository Dependent on not published jar ? mvninstall:install-file System scope (systemPath) File Repository
Inheritance & Multiply-module Inheritance Dependencies Plugin lists/executions/configuration Properties (Yes) Profile is not inherited directly but activated Multiply-Module (Aggregation, a single command:) <parent> <groupId>com.telenav</groupId> <artifactId>geoalert-masterpom</artifactId> <version>1.0.0</version> </parent> <modules>     <module>my-project</module>        <module>another-project</module>  </modules>
Maven-Plugin Extends AbstractMojo Project Definition <packaging>maven-plugin</packaging> Parameters : inject by Maven (IOC) Annotation     /*  extra files/folders to classpath      * @parameter      */ protected File[]extraClassPathItems; <configuration> <extraClassPathItems> <extraClassPathItem>src/main/webapp</extraClassPathItem> </extraClassPathItems> </configuration>                /** 	 * Location of class files 	 * 	 * @parameter expression="${project.build.outputDrectory}" 	 * @required 	 */ private File outputDirectory;
ANT vs Maven Declarative (Maven) and Imperative (Ant) Convention and configuration (Maven) over configuration and scripting (Ant) Ant dist(Defaut) generate-java init clean compile <target name=“dist” depends=“generate-java, compile”/> generate-resources Maven compile compiler:compile test surefire:test Standard project layout pakcage surefire:test install Build-in Phases Build-in Goals
Ant vs Maven Maven Good for Modularization Dependency management Not easy for beginner to understand Bugs and issues are hard to track (understand the conventions) Sometimes are slow Ant Easy to learn – No so many abstraction
Reference Reference http://www.sonatype.com/books/mvnref-book/reference/public-book.html http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html Deploy use Maven http://jlorenzen.blogspot.com/2007/09/how-to-effectively-use-snapshot.html http://java.dzone.com/articles/getting-started-nexus-maven Release use Maven http://jlorenzen.blogspot.com/2007/09/how-to-create-release-using-maven2.html http://maven.apache.org/guides/mini/guide-releasing.html

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Apache Maven
Apache MavenApache Maven
Apache Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Maven
MavenMaven
Maven
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Maven
Maven Maven
Maven
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 

Semelhante a Maven

Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldDmitry Bakaleinik
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolelliando dias
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialRaghavan Mohan
 
Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternselliando dias
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2Shuji Watanabe
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationArnaud Héritier
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...Jesse Gallagher
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGirish Bapat
 

Semelhante a Maven (20)

Using Maven2
Using Maven2Using Maven2
Using Maven2
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Maven
MavenMaven
Maven
 
Introduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS worldIntroduction to maven, its configuration, lifecycle and relationship to JS world
Introduction to maven, its configuration, lifecycle and relationship to JS world
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 
Maven
MavenMaven
Maven
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patterns
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
 
Maven
MavenMaven
Maven
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentation
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Getting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydbGetting started with agile database migrations for java flywaydb
Getting started with agile database migrations for java flywaydb
 
P&MSP2012 - Maven
P&MSP2012 - MavenP&MSP2012 - Maven
P&MSP2012 - Maven
 

Mais de feng lee

Guice in athena
Guice in athenaGuice in athena
Guice in athenafeng lee
 
Bloom filter
Bloom filterBloom filter
Bloom filterfeng lee
 
Hadoop 安装
Hadoop 安装Hadoop 安装
Hadoop 安装feng lee
 
Axis2 client memory leak
Axis2 client memory leakAxis2 client memory leak
Axis2 client memory leakfeng lee
 
Mysql story in poi dedup
Mysql story in poi dedupMysql story in poi dedup
Mysql story in poi dedupfeng lee
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrencyfeng lee
 

Mais de feng lee (6)

Guice in athena
Guice in athenaGuice in athena
Guice in athena
 
Bloom filter
Bloom filterBloom filter
Bloom filter
 
Hadoop 安装
Hadoop 安装Hadoop 安装
Hadoop 安装
 
Axis2 client memory leak
Axis2 client memory leakAxis2 client memory leak
Axis2 client memory leak
 
Mysql story in poi dedup
Mysql story in poi dedupMysql story in poi dedup
Mysql story in poi dedup
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
 

Último

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Último (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Maven

  • 2. Preface Do you ever begin a new project from scratch? What’s you do before your first line code? Do you maintain the build script in your Team? Which kinds of tool do you use (make, ant, ivy, maven, mercury,…)
  • 3. Outline Key concept Basic Usage Demo 20% usage Ant vs Maven
  • 5. Plugin : (task in Ant) Maven is a plugin execution framework. Adding functionality to Maven is done through the plugin mechanism. (all work is done by plugins) Similar to Ant Task/Ant Target(not exactly) from the user view A collection of goals (tasks)
  • 7. Plugin Ant Maven <targetname="compile"depends="init"description="compile the source "> <!-- Compile the java code from ${src} into ${build} --> <javacsrcdir="${src}"destdir="${build}"source="1.6"target="1.6"/> </target> <build> … <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> … </build>
  • 8. Lifecycle : the plugin-goal (task) execution sequence <projectname="MyProject"default="dist"basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <propertyname="src"location="src"/> <propertyname="build"location="build"/> <propertyname="dist"location="dist"/> <targetname="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdirdir="${build}"/> </target> <targetname="compile"depends="init"description="compile the source "> <!-- Compile the java code from ${src} into ${build} --> <javacsrcdir="${src}"destdir="${build}"/> </target> <targetname="dist"depends="compile"description="generate the distribution"> <!-- Create the distribution directory --> <mkdirdir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jarjarfile="${dist}/lib/MyProject-${DSTAMP}.jar"basedir="${build}"/> </target> <targetname="clean"description="clean up"> <!-- Delete the ${build} and ${dist} directory trees --> <deletedir="${build}"/> <deletedir="${dist}"/> </target> </project>
  • 9. Lifecycle : the plugin-goal (task) execution sequence goals( pluginname:goalname) default
  • 10. Lifecycle A lifecycle is made up of phases These build phases are executed sequentially (including all of the prior steps) A Build phase is made up of goals A goal represents a specific task, minimum execute unit (task) A goal is bound to zero (direct invocation) or more build phases mvn jar:jar ----------- plugin-goal prefix-name (mvngroupID:artifactID:version:goal) mvn package ----------- lifecycle phase name ,would execute jar:jar, because jar:jar is one contained goal in package phase
  • 11. Lifecycle: build-in lifecycle default clean site
  • 13. Lifecycle : adding more goals by plugin Plugin: are artifacts that provide goals (tasks) to Maven <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <configuration> <outputDirectory>doc</outputDirectory> <show>public</show> <nohelp>true</nohelp> <windowtitle>TNT-CAL API doc</windowtitle> <doctitle>TNT-CAL API doc</doctitle> <maxmemory>256m</maxmemory> <sourcepath>src/main/java</sourcepath> <charset>utf8</charset> <locale>en_us</locale> </configuration> <executions> <execution> <id>api-doc</id> <phase>prepare-package</phase> <goals> <goal>javadoc</goal> </goals> </execution> </executions> </plugin>
  • 14. Dependency: no flying jars No need download dependency lib one by one, declare it, Maven download for you Shrink the project size in svn <dependencies> … <dependency> <groupId>com.telenav</groupId> <artifactId>ace-client</artifactId> <version>1.0.0.15</version> <classifier>release</classifier> <type>jar</type> </dependency> <dependency> <groupId>com.telenav</groupId> <artifactId>kernel</artifactId> <version>a1.3-b101</version> <type>jar</type> </dependency> … </dependencies>
  • 15. Dependency: transitive Compile ok, runtime ‘NoClassDefFoundError’ ---- Need transitive jar Transitive (Chain) A -> B -> C Transitive config Shortest path A -> B -> C -> D 2.0 and A -> E -> D 1.0 Dependency scope Dependency management : inheritance; import
  • 16. Dependency: transitive Dependency scope (IVY configuration map) C (compile) B (compile) A D (runtime) E (test) compile test runtime
  • 17. Profile Different build configuration for different target environments Different OS Different deploy environment Activation  -P CLI option Based on environment variables… Maven will execute the steps in the profile in addition to the normal steps
  • 18. Profile <profiles> <profile> <id>cn-dev</id> <activation> <property> <name>target</name> <value>cn-dev</value> </property> </activation> <properties> <encoding>gb2312</encoding> </properties> </profile> <profile> <id>us-deploy</id> <activation> <property> <name>target</name> <value>us-deploy</value> </property> </activation> <properties> <skipTests>true</skipTests> </properties> </profile> </profiles>
  • 20. Create a project Create mvn archetype:generate –DarchetypeArtifactId=maven-archetype-quickstart –DgroupId=com.telenav –DartificatId=rgc Project layout http://stackoverflow.com/questions/4182794/in-maven-what-is-the-difference-between-main-resources-and-main-config
  • 21. Demo : Hello World Build Package Test Report Install/Deploy/Release mvn install: to local repository mvndeploy: to remote (release) repository mvn release: deploy and tag the source code by scm.
  • 22. 20% usage Eclipse plugin Properties Repository Inheritance & Multiply-module Write a maven-plugin
  • 24. Properties Build in properties ${basedir} represents the directory containing pom.xml ${project.basedir} represents the directory containing pom.xml Project properties <project><version>1.0</version></project> is accessible via ${project.version}. Environment variables ${env.PATH} Java System Properties ${file.separator} User-defined Properties Plugin property expression: ${maven.compiler.target} Setting property
  • 25. Repository Add repository (Telenav) <repositories> <repository> <id>telenav</id> <url>http://tar1.telenav.com:8080/repository</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
  • 26. Repository (Deploy) Distribution artifacts to release repository <distributionManagement> <repository> <id>nexus</id> <url>http://192.168.109.118:8080/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus</id> <url>http://192.168.109.118:8080/nexus/content/repositories/snapshots/</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> </disctributionmanagement> // $M2_HOME/conf/settings.xml // scp password or nexus deploy password or tomcat manage password, dependent on distribute url <servers> <server> <id>maven2-snapshot-repository</id> <username>repoman</username> <password>mypassword</password> </server><servers>
  • 27. Repository (Release) <build> <plugins> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.0-beta-9</version> <configuration> <tagBase> http://svn.telenav.com/tnt/Backend/tntcal/tags/tntcal-core </tagBase> </configuration> </plugin> </plugins> </build> <scm> <developerConnection>scm:svn:http://svn.telenav.com/tnt/Backend/tntcal/trunk</developerConnection> </scm>
  • 28. Repository Dependent on not published jar ? mvninstall:install-file System scope (systemPath) File Repository
  • 29. Inheritance & Multiply-module Inheritance Dependencies Plugin lists/executions/configuration Properties (Yes) Profile is not inherited directly but activated Multiply-Module (Aggregation, a single command:) <parent> <groupId>com.telenav</groupId> <artifactId>geoalert-masterpom</artifactId> <version>1.0.0</version> </parent> <modules> <module>my-project</module> <module>another-project</module> </modules>
  • 30. Maven-Plugin Extends AbstractMojo Project Definition <packaging>maven-plugin</packaging> Parameters : inject by Maven (IOC) Annotation /* extra files/folders to classpath * @parameter */ protected File[]extraClassPathItems; <configuration> <extraClassPathItems> <extraClassPathItem>src/main/webapp</extraClassPathItem> </extraClassPathItems> </configuration> /** * Location of class files * * @parameter expression="${project.build.outputDrectory}" * @required */ private File outputDirectory;
  • 31. ANT vs Maven Declarative (Maven) and Imperative (Ant) Convention and configuration (Maven) over configuration and scripting (Ant) Ant dist(Defaut) generate-java init clean compile <target name=“dist” depends=“generate-java, compile”/> generate-resources Maven compile compiler:compile test surefire:test Standard project layout pakcage surefire:test install Build-in Phases Build-in Goals
  • 32. Ant vs Maven Maven Good for Modularization Dependency management Not easy for beginner to understand Bugs and issues are hard to track (understand the conventions) Sometimes are slow Ant Easy to learn – No so many abstraction
  • 33. Reference Reference http://www.sonatype.com/books/mvnref-book/reference/public-book.html http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html Deploy use Maven http://jlorenzen.blogspot.com/2007/09/how-to-effectively-use-snapshot.html http://java.dzone.com/articles/getting-started-nexus-maven Release use Maven http://jlorenzen.blogspot.com/2007/09/how-to-create-release-using-maven2.html http://maven.apache.org/guides/mini/guide-releasing.html

Notas do Editor

  1. mvncompilemvn packagemvn testmvneclipse:elipse