SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Kürzlich hochgeladen (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

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

Hinweis der Redaktion

  1. mvncompilemvn packagemvn testmvneclipse:elipse