SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Dernier (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

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

Notes de l'éditeur

  1. mvncompilemvn packagemvn testmvneclipse:elipse