SlideShare a Scribd company logo
Using Maven2
Free Maven Books Maven: The Definitive Guide (alpha)‏ www.sonatype.com/book Better Builds with Maven www.mergere.com
The Maven Site http://maven.apache.org/
What is Maven? Build lifecycle Dependency management tool Artifact repository Collection of plugins Project reporting tool Set of conventions Distilled experience
What Else is Maven? Succinct command line tool Designed for Java/Java EE/other Holder/publisher of project documentation Generator of project metrics Customisable: environment, lifecycle, etc Inheritable Declarative Encourager of modularity and reuse Integrated with SCM tools Integrated with IDEs Integrated with Ant System of repositories Project kick starter Release manager Deployer Enabler of portable build knowledge Encourager of best practice Community Not perfect
Quick Start Download Maven2, unzip, add bin directory to $PATH Configure proxy in ~/.m2/settings.xml if required $ mvn archetype:create  \ -DgroupId=com.example  \ -DartifactId=my-app
Directory Structure Convention Java sources: src/main/java Unit tests: src/test/java pom.xml
pom.xml – The Project Object Model <project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;> <modelVersion>4.0.0</modelVersion> <groupId> com.example </groupId> <artifactId> my-app </artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
Directory Structure Convention Added: My app sources Properties file: src/main/resources/ messages.poperties My unit test
Killer App package com.example; public class Hello { public static void main(String[] args){ ResourceBundle messages = ResourceBundle.getBundle(&quot;messages&quot;); MessagePrinter mp = new MessagePrinter(); mp.printMessage(messages.getString(&quot;message1&quot;), System.out); mp.printMessage(&quot;\n&quot;, System.out); } } public class MessagePrinter { public void printMessage(String message, OutputStream os){ PrintWriter pw = new PrintWriter(os); pw.print(message); pw.flush(); } }
My Application POM <project ...> ... <name> My Application </name> <url>http://localhost:8080/my-app</url> ... <build> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> com.example.Hello </mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>
Eclipse Integration Maven2 plugin for Eclipse;  either  from project root execute: $ mvn eclipse:eclipse and import with Eclipse,  or  create the project in Eclipse and add the Maven2 project nature
Eclipse Integration
Ready for Take Off $ mvn package
stdout [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building My Application [INFO]  task-segment: [package] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: /home/russell/Desktop/maven-presentation/example/my-app/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.example.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: /home/russell/Desktop/maven-presentation/example/my-app/target/my-app-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Wed Jul 04 11:11:55 NZST 2007 [INFO] Final Memory: 4M/11M [INFO] ------------------------------------------------------------------------
The (Almost) Finished Product Classes and test classes compiled Resources copied to classes directory Test reports created Jar file created $ java -jar my-app-1.0-SNAPSHOT.jar Hello World!
Plugins & Goals A plugin contains one or more goals (Goal a.k.a. Mojo; Maven + Pojo = Mojo   ?!@! )‏ A plugin is a Maven artifact A goal is uniquely referenced/invoked by: groupId:artifactId:version:goal e.g: org.apache.maven.plugins:maven-eclipse-plugin:eclipse defaults shorten this to: eclipse:eclipse
Anatomy of a Maven Command 1. Invoke a specific goal: $ mvn [options] plugin:goal [parameter]... e.g: $ mvn -e eclipse:eclipse -> Generate Eclipse configuration, print verbose error messages 2. Invoke goals bound to the lifecycle(s) up to and including a phase: $ mvn [options] phase... [parameter]... e.g: $ mvn clean package -Dmaven.test.skip=true ->  Clean target, build package, skip tests
Maven Lifecycles Three built-in lifecycles: default clean site You can create your own lifecycle, but only if you have really weird build requirements!
The Default Build Lifecycle
Project Packaging <project ...> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-app</artifactId> <packaging> jar </packaging> <version>1.0-SNAPSHOT</version> ... </project>
Lifecycle Bindings
Build Lifecycle $ mvn package
stdout [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building My Application [INFO]  task-segment: [package] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: /home/russell/Desktop/maven-presentation/example/my-app/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.example.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: /home/russell/Desktop/maven-presentation/example/my-app/target/my-app-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Wed Jul 04 11:11:55 NZST 2007 [INFO] Final Memory: 4M/11M [INFO] ------------------------------------------------------------------------
Dependencies <project ...> ... <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> Explicitly declared, including version Resolved by Maven, not required in project directory / source control repository Scoped: compile, provided, runtime, test SNAPSHOT dependencies updated Transitive Strictly acyclic (a DAG not a tree)‏
Killer App Reloaded public class Hello { public static void main(String[] args) { ReloadableResourceBundleMessageSource messages = new ReloadableResourceBundleMessageSource(); messages.setCacheSeconds(1); messages.setBasename(&quot;messages&quot;); MessagePrinter mp = new MessagePrinter(); Scanner scanner = new Scanner(System.in); do { String message = messages.getMessage(&quot;message1&quot;, null, Locale.getDefault()); mp.printMessage(message, System.out); mp.printMessage(&quot;\n&quot;, System.out); mp.printMessage(&quot;Keep playing? [Y/n]\n&quot;, System.out); } while (!&quot;n&quot;.equals(scanner.nextLine())); } }
Dependencies <project ...> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version> [2.0,) </version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </exclusion> ...   </project> Version ranges Use exclusions to trim unwanted dependencies
Transitive Dependencies
Reloadable Message Source Hello World! Keep playing? [Y/n] y Hello Again World! Keep playing? [Y/n] n Note for anyone trying this at home: there's a bit of classpath config required to get this working nicely. It's easiest to run it on the Eclipse console, and modify the target messages.properties
Configuring Plugins e.g. Ant <project...> ... <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <configuration> <tasks> <!-- Place any ant task here. You can add anything you can add between <target> and </target> in a build.xml. --> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Standard Maven Plugins clean compiler deploy install resources site surefire verifier ear ejb jar rar war changelog changes checkstyle clover doap docck javadoc jxr pmd project-info-reports surefire-report ant antlr antrun archetype assembly dependency enforcer gpg help invoker one plugin release remote-resources repository scm source eclipse idea Codehaus: build-helper castor javacc jdepend native sql taglist Other: cargo jaxme jetty jalopy Listed at: http://maven.apache.org/plugins/
POM Inheritance <project> <modelVersion>4.0.0</modelVersion> <groupId> com.example </groupId> <artifactId> my-app </artifactId> <version>1.0-SNAPSHOT</version> </project> No source or target defined in POM, yet this works: $ mvn compile
Super POM <project> <build> ... <outputDirectory> target/classes </outputDirectory> ... <sourceDirectory> src/main/java </sourceDirectory> ... <resources> <resource> <directory> src/main/resources </directory> </resource> </resources> ... </build> </project> To fully resolve the POM: $ mvn help:effective-pom | less
POM Inheritance <project> <parent> <groupId>com.example</groupId> <artifactId>org-pom</artifactId> <version>1</version> </parent> <groupId>com.example</groupId> <artifactId>my-app</artifactId> ... </project> <project> <groupId>com.example</groupId> <artifactId>org-pom</artifactId> <version>1</version> <!-- configure JDK version, e.g: 1.5 standard reports, etc. --> </project>
Maven Repositories Repositories store artifacts: plugins project dependencies Central:  http://repo1.maven.org/maven2 (or mirror)‏ Local: ~/.m2/repository The first execution of a plugin, or requirement for a dependency pulls the artifact from central and caches it locally
Maven Repositories Problems: Reliant on network and external repository for dependencies and plugins Can't deploy to Central Maven repository for reuse as dependencies of other projects (though usually wouldn't want to)‏
Organisation Repository No longer reliant on network or external repository for dependencies and plugins Can deploy to organisation repository in order to share artifacts Multiple repository configurations possible Multiple repository tools available: Archiva, Proximity, Artifactory
Archiva
Install and Deploy $ mvn deploy
Install and Deploy $ mvn deploy
SCM Integration Fully implemented: Bazaar CVS Mercurial Perforce StarTeam Subversion CM Synergy Partially implemented: ClearCase File system Visual Source Safe
Configuring SCM <project> <groupId>com.example</groupId> <artifactId>my-app</artifactId> ... <scm> <connection> scm:svn:http://example.com/svn-read/my-app/trunk   </connection> <developerConnection> scm:svn:http://example.com/svn-dev/my-app/trunk </developerConnection> <url> http://example.com/view.cvs </url> </scm> </project>
SCM Integration, What For? Use SCM agnostic commands: $ mvn scm:checkin -Dmessage=&quot;to the cause&quot; $ mvn scm:update Project bootstrapping:  $ mvn scm:bootstrap Available for use by Maven tools, e.g: documented and linked in project website, published in Archiva summary Continuous Integration, SCM details located in project rather than CI tool Release management
Cutting a Release $ mvn release:prepare [-DdryRun=true] Checks SCM for modifications Checks for use of SNAPSHOT dependencies or plugins Runs $ mvn clean integration-test Requests release info: version numbers Creates new POMs: pom.xml for tag pom.xml for next version release-pom.xml Creates tag in SCM $ mvn release:perform Uses release-pom.xml, deploys project, generates site, etc.
Website / Reports (1)‏ Project website: Conventions for structuring documentation, supporting various formats: DocBook simple, FML, XDOC, APT, Twiki Directory structure conventions, supporting multiple types of documentation, e.g: public, user, developer, etc. Configurable, skinnable site Project info from POM: contact details: organisation, developers; SCM details, etc.
Website / Reports (2)‏ Metrics, checks, and project reports (on website): Javadoc Test results Code coverage (Cobertura)‏ Checkstyle, PMD, JDepend, Clirr Database documentation (Hibernate)‏ Dependency report TODO report (//TODO, FIXME, configurable)‏ Linked and line-numbered HTML sources Release notes and roadmap from issue tracker
Quick Tour
In Brief (1)‏ Java EE support: WAR, EAR packaging Rapid web app development Integration (in container) testing Deployment to environments Multi-module projects Enable / encourage reuse between projects Maven inter-module dependency eliminates cycles between modules Nicely supported in NetBeans Not nicely supported in Eclipse – nested projects
In Brief (2)‏ Continuous Integration: CruiseControl Continuum Reuses project information as defined in POM Profiles Build activity carried out under different conditions, e.g: personal requirements, dev / test / release, continuous integration Maven settings Help
Problems History: Maven 1, might have left a bad taste Steep learning curve Once you've got it, the knowledge is portable to other projects built with Maven Complex needs require complex configuration Alan Kay: Simple things should be simple. Complex things should be possible Verbose XML config Docs aren't great, but getting better Error messages often do not provide much (or any) detail (e.g. archetype problem)‏ Ensuring the project is buildable and testable in the IDE as well as with Maven can be complex Multi-module projects not supported by Eclipse (but they are in Netbeans)‏
Stuff to Look at Buildr – a build system configured in Ruby that reuses parts of Maven: repositories; directory structure conventions; Rake – a Ruby build tool
Still Interested? Get reading and enjoy the ride
Questions?
Ad

More Related Content

What's hot (20)

Development Tools - Maven
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
Bert Koorengevel
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
andyhot
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
boyw165
 
Maven 2 Introduction
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
Valentin Jacquemin
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
FastConnect
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
James Cellini
 
Apache Maven
Apache MavenApache Maven
Apache Maven
Rahul Tanwani
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
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
chrisb206 chrisb206
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
Log management (elk) for spring boot application
Log management (elk) for spring boot applicationLog management (elk) for spring boot application
Log management (elk) for spring boot application
Vadym Lotar
 
Maven ppt
Maven pptMaven ppt
Maven ppt
natashasweety7
 
Maven tutorial for beginners
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
inTwentyEight Minutes
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
andyhot
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
Vadym Lotar
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
boyw165
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
Smita Prasad
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
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
chrisb206 chrisb206
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed
 
Log management (elk) for spring boot application
Log management (elk) for spring boot applicationLog management (elk) for spring boot application
Log management (elk) for spring boot application
Vadym Lotar
 

Similar to Using Maven2 (20)

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
elliando dias
 
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
elliando dias
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 
Maven
MavenMaven
Maven
Fabio Bonfante
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentation
Arnaud Héritier
 
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development EnvironmentJoget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
Carlos Sanchez
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
Shuji Watanabe
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
Evgeny Goldin
 
Slim3 quick start
Slim3 quick startSlim3 quick start
Slim3 quick start
Guangyao Cao
 
Introduction To Eclipse RCP
Introduction To Eclipse RCPIntroduction To Eclipse RCP
Introduction To Eclipse RCP
whbath
 
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
Dmitry Bakaleinik
 
Maven, Eclipse And OSGi Working Together
Maven, Eclipse And OSGi Working TogetherMaven, Eclipse And OSGi Working Together
Maven, Eclipse And OSGi Working Together
Carlos Sanchez
 
Apache Maven basics
Apache Maven basicsApache Maven basics
Apache Maven basics
Volodymyr Ostapiv
 
Maven
MavenMaven
Maven
Shraddha
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
Martin Jackson
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN Controller
Sumit Arora
 
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
 
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
Sencha
 
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
elliando dias
 
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
elliando dias
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentation
Arnaud Héritier
 
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development EnvironmentJoget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow
 
Enterprise Build And Test In The Cloud
Enterprise Build And Test In The CloudEnterprise Build And Test In The Cloud
Enterprise Build And Test In The Cloud
Carlos Sanchez
 
Introduction To Maven2
Introduction To Maven2Introduction To Maven2
Introduction To Maven2
Shuji Watanabe
 
Introduction To Eclipse RCP
Introduction To Eclipse RCPIntroduction To Eclipse RCP
Introduction To Eclipse RCP
whbath
 
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
Dmitry Bakaleinik
 
Maven, Eclipse And OSGi Working Together
Maven, Eclipse And OSGi Working TogetherMaven, Eclipse And OSGi Working Together
Maven, Eclipse And OSGi Working Together
Carlos Sanchez
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
Martin Jackson
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN Controller
Sumit Arora
 
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
 
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
Sencha
 
Ad

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
Ragel talk
Ragel talkRagel talk
Ragel talk
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Rango
RangoRango
Rango
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
Ad

Recently uploaded (20)

Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 

Using Maven2

  • 2. Free Maven Books Maven: The Definitive Guide (alpha)‏ www.sonatype.com/book Better Builds with Maven www.mergere.com
  • 3. The Maven Site http://maven.apache.org/
  • 4. What is Maven? Build lifecycle Dependency management tool Artifact repository Collection of plugins Project reporting tool Set of conventions Distilled experience
  • 5. What Else is Maven? Succinct command line tool Designed for Java/Java EE/other Holder/publisher of project documentation Generator of project metrics Customisable: environment, lifecycle, etc Inheritable Declarative Encourager of modularity and reuse Integrated with SCM tools Integrated with IDEs Integrated with Ant System of repositories Project kick starter Release manager Deployer Enabler of portable build knowledge Encourager of best practice Community Not perfect
  • 6. Quick Start Download Maven2, unzip, add bin directory to $PATH Configure proxy in ~/.m2/settings.xml if required $ mvn archetype:create \ -DgroupId=com.example \ -DartifactId=my-app
  • 7. Directory Structure Convention Java sources: src/main/java Unit tests: src/test/java pom.xml
  • 8. pom.xml – The Project Object Model <project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;> <modelVersion>4.0.0</modelVersion> <groupId> com.example </groupId> <artifactId> my-app </artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
  • 9. Directory Structure Convention Added: My app sources Properties file: src/main/resources/ messages.poperties My unit test
  • 10. Killer App package com.example; public class Hello { public static void main(String[] args){ ResourceBundle messages = ResourceBundle.getBundle(&quot;messages&quot;); MessagePrinter mp = new MessagePrinter(); mp.printMessage(messages.getString(&quot;message1&quot;), System.out); mp.printMessage(&quot;\n&quot;, System.out); } } public class MessagePrinter { public void printMessage(String message, OutputStream os){ PrintWriter pw = new PrintWriter(os); pw.print(message); pw.flush(); } }
  • 11. My Application POM <project ...> ... <name> My Application </name> <url>http://localhost:8080/my-app</url> ... <build> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> com.example.Hello </mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>
  • 12. Eclipse Integration Maven2 plugin for Eclipse; either from project root execute: $ mvn eclipse:eclipse and import with Eclipse, or create the project in Eclipse and add the Maven2 project nature
  • 14. Ready for Take Off $ mvn package
  • 15. stdout [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building My Application [INFO] task-segment: [package] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: /home/russell/Desktop/maven-presentation/example/my-app/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.example.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: /home/russell/Desktop/maven-presentation/example/my-app/target/my-app-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Wed Jul 04 11:11:55 NZST 2007 [INFO] Final Memory: 4M/11M [INFO] ------------------------------------------------------------------------
  • 16. The (Almost) Finished Product Classes and test classes compiled Resources copied to classes directory Test reports created Jar file created $ java -jar my-app-1.0-SNAPSHOT.jar Hello World!
  • 17. Plugins & Goals A plugin contains one or more goals (Goal a.k.a. Mojo; Maven + Pojo = Mojo  ?!@! )‏ A plugin is a Maven artifact A goal is uniquely referenced/invoked by: groupId:artifactId:version:goal e.g: org.apache.maven.plugins:maven-eclipse-plugin:eclipse defaults shorten this to: eclipse:eclipse
  • 18. Anatomy of a Maven Command 1. Invoke a specific goal: $ mvn [options] plugin:goal [parameter]... e.g: $ mvn -e eclipse:eclipse -> Generate Eclipse configuration, print verbose error messages 2. Invoke goals bound to the lifecycle(s) up to and including a phase: $ mvn [options] phase... [parameter]... e.g: $ mvn clean package -Dmaven.test.skip=true -> Clean target, build package, skip tests
  • 19. Maven Lifecycles Three built-in lifecycles: default clean site You can create your own lifecycle, but only if you have really weird build requirements!
  • 20. The Default Build Lifecycle
  • 21. Project Packaging <project ...> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-app</artifactId> <packaging> jar </packaging> <version>1.0-SNAPSHOT</version> ... </project>
  • 23. Build Lifecycle $ mvn package
  • 24. stdout [INFO] Scanning for projects... [INFO] ---------------------------------------------------------------------------- [INFO] Building My Application [INFO] task-segment: [package] [INFO] ---------------------------------------------------------------------------- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/classes [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] Compiling 1 source file to /home/russell/Desktop/maven-presentation/example/my-app/target/test-classes [INFO] [surefire:test] [INFO] Surefire report directory: /home/russell/Desktop/maven-presentation/example/my-app/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.example.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: /home/russell/Desktop/maven-presentation/example/my-app/target/my-app-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Wed Jul 04 11:11:55 NZST 2007 [INFO] Final Memory: 4M/11M [INFO] ------------------------------------------------------------------------
  • 25. Dependencies <project ...> ... <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> Explicitly declared, including version Resolved by Maven, not required in project directory / source control repository Scoped: compile, provided, runtime, test SNAPSHOT dependencies updated Transitive Strictly acyclic (a DAG not a tree)‏
  • 26. Killer App Reloaded public class Hello { public static void main(String[] args) { ReloadableResourceBundleMessageSource messages = new ReloadableResourceBundleMessageSource(); messages.setCacheSeconds(1); messages.setBasename(&quot;messages&quot;); MessagePrinter mp = new MessagePrinter(); Scanner scanner = new Scanner(System.in); do { String message = messages.getMessage(&quot;message1&quot;, null, Locale.getDefault()); mp.printMessage(message, System.out); mp.printMessage(&quot;\n&quot;, System.out); mp.printMessage(&quot;Keep playing? [Y/n]\n&quot;, System.out); } while (!&quot;n&quot;.equals(scanner.nextLine())); } }
  • 27. Dependencies <project ...> ... <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version> [2.0,) </version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </exclusion> ... </project> Version ranges Use exclusions to trim unwanted dependencies
  • 29. Reloadable Message Source Hello World! Keep playing? [Y/n] y Hello Again World! Keep playing? [Y/n] n Note for anyone trying this at home: there's a bit of classpath config required to get this working nicely. It's easiest to run it on the Eclipse console, and modify the target messages.properties
  • 30. Configuring Plugins e.g. Ant <project...> ... <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <configuration> <tasks> <!-- Place any ant task here. You can add anything you can add between <target> and </target> in a build.xml. --> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
  • 31. Standard Maven Plugins clean compiler deploy install resources site surefire verifier ear ejb jar rar war changelog changes checkstyle clover doap docck javadoc jxr pmd project-info-reports surefire-report ant antlr antrun archetype assembly dependency enforcer gpg help invoker one plugin release remote-resources repository scm source eclipse idea Codehaus: build-helper castor javacc jdepend native sql taglist Other: cargo jaxme jetty jalopy Listed at: http://maven.apache.org/plugins/
  • 32. POM Inheritance <project> <modelVersion>4.0.0</modelVersion> <groupId> com.example </groupId> <artifactId> my-app </artifactId> <version>1.0-SNAPSHOT</version> </project> No source or target defined in POM, yet this works: $ mvn compile
  • 33. Super POM <project> <build> ... <outputDirectory> target/classes </outputDirectory> ... <sourceDirectory> src/main/java </sourceDirectory> ... <resources> <resource> <directory> src/main/resources </directory> </resource> </resources> ... </build> </project> To fully resolve the POM: $ mvn help:effective-pom | less
  • 34. POM Inheritance <project> <parent> <groupId>com.example</groupId> <artifactId>org-pom</artifactId> <version>1</version> </parent> <groupId>com.example</groupId> <artifactId>my-app</artifactId> ... </project> <project> <groupId>com.example</groupId> <artifactId>org-pom</artifactId> <version>1</version> <!-- configure JDK version, e.g: 1.5 standard reports, etc. --> </project>
  • 35. Maven Repositories Repositories store artifacts: plugins project dependencies Central: http://repo1.maven.org/maven2 (or mirror)‏ Local: ~/.m2/repository The first execution of a plugin, or requirement for a dependency pulls the artifact from central and caches it locally
  • 36. Maven Repositories Problems: Reliant on network and external repository for dependencies and plugins Can't deploy to Central Maven repository for reuse as dependencies of other projects (though usually wouldn't want to)‏
  • 37. Organisation Repository No longer reliant on network or external repository for dependencies and plugins Can deploy to organisation repository in order to share artifacts Multiple repository configurations possible Multiple repository tools available: Archiva, Proximity, Artifactory
  • 39. Install and Deploy $ mvn deploy
  • 40. Install and Deploy $ mvn deploy
  • 41. SCM Integration Fully implemented: Bazaar CVS Mercurial Perforce StarTeam Subversion CM Synergy Partially implemented: ClearCase File system Visual Source Safe
  • 42. Configuring SCM <project> <groupId>com.example</groupId> <artifactId>my-app</artifactId> ... <scm> <connection> scm:svn:http://example.com/svn-read/my-app/trunk </connection> <developerConnection> scm:svn:http://example.com/svn-dev/my-app/trunk </developerConnection> <url> http://example.com/view.cvs </url> </scm> </project>
  • 43. SCM Integration, What For? Use SCM agnostic commands: $ mvn scm:checkin -Dmessage=&quot;to the cause&quot; $ mvn scm:update Project bootstrapping: $ mvn scm:bootstrap Available for use by Maven tools, e.g: documented and linked in project website, published in Archiva summary Continuous Integration, SCM details located in project rather than CI tool Release management
  • 44. Cutting a Release $ mvn release:prepare [-DdryRun=true] Checks SCM for modifications Checks for use of SNAPSHOT dependencies or plugins Runs $ mvn clean integration-test Requests release info: version numbers Creates new POMs: pom.xml for tag pom.xml for next version release-pom.xml Creates tag in SCM $ mvn release:perform Uses release-pom.xml, deploys project, generates site, etc.
  • 45. Website / Reports (1)‏ Project website: Conventions for structuring documentation, supporting various formats: DocBook simple, FML, XDOC, APT, Twiki Directory structure conventions, supporting multiple types of documentation, e.g: public, user, developer, etc. Configurable, skinnable site Project info from POM: contact details: organisation, developers; SCM details, etc.
  • 46. Website / Reports (2)‏ Metrics, checks, and project reports (on website): Javadoc Test results Code coverage (Cobertura)‏ Checkstyle, PMD, JDepend, Clirr Database documentation (Hibernate)‏ Dependency report TODO report (//TODO, FIXME, configurable)‏ Linked and line-numbered HTML sources Release notes and roadmap from issue tracker
  • 48. In Brief (1)‏ Java EE support: WAR, EAR packaging Rapid web app development Integration (in container) testing Deployment to environments Multi-module projects Enable / encourage reuse between projects Maven inter-module dependency eliminates cycles between modules Nicely supported in NetBeans Not nicely supported in Eclipse – nested projects
  • 49. In Brief (2)‏ Continuous Integration: CruiseControl Continuum Reuses project information as defined in POM Profiles Build activity carried out under different conditions, e.g: personal requirements, dev / test / release, continuous integration Maven settings Help
  • 50. Problems History: Maven 1, might have left a bad taste Steep learning curve Once you've got it, the knowledge is portable to other projects built with Maven Complex needs require complex configuration Alan Kay: Simple things should be simple. Complex things should be possible Verbose XML config Docs aren't great, but getting better Error messages often do not provide much (or any) detail (e.g. archetype problem)‏ Ensuring the project is buildable and testable in the IDE as well as with Maven can be complex Multi-module projects not supported by Eclipse (but they are in Netbeans)‏
  • 51. Stuff to Look at Buildr – a build system configured in Ruby that reuses parts of Maven: repositories; directory structure conventions; Rake – a Ruby build tool
  • 52. Still Interested? Get reading and enjoy the ride