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

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

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