SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
Pasadena Java Users Group
pasadenajug.org




Java Builds
with Ant & Maven
Feb 23, 2009




David Noble
dnoble@g2ix.com
About Me
David Noble
Sr Solutions Architect
Exist Global / G2iX
About You
    Ant users? Ivy?



    Maven users?



    Continuous integration?

Build Tool
    Collect inputs



    Process inputs



    Generate final outputs

Build Tool - Inputs
    Source code



        Java, SQL
    



    Resources



        Properties, XML
    



    Dependencies



        Libraries, components, frameworks
    
Build Tool - Processing
    Compile



    Run tests



    Copy files



    Replace keywords



    Package



    Install / deploy

Build Tool - Outputs
    JAR / WAR / EAR files



    Zip files



    Reports

Ant                 Maven
Procedural          Declarative
1. Set path         1. Define name & version
2. Compile jars     2. Define as WAR project
3. Run unit tests   3. Specify dependencies
4. Create reports   4. Specify unit test plugin
5. Copy files
6. Assemble WAR
Ant
    “make for java”



    Properties, paths, and filesets



    Targets



    Target dependencies



    Tasks

Ant Installation
    Download



    Unzip



    Add to PATH



    Set ANT_HOME env variable



    Extend by adding jars to lib/



    Customize by modifying XSL in etc/

Ant Project Definition
build.xml
    Project name



    Property variables



    Paths



    Tasks



    Targets

Ant Properties
<property name=quot;lib.dirquot; value=quot;libquot;/>
    From command line



    In build.xml



    From external XML



    From external property files



    From environment

Ant Paths
<path id=quot;classpathquot;>
 <fileset dir=quot;${lib.dir}quot; includes=quot;**/*.jarquot;/>
</path>


<target name=quot;compilequot;>
 <mkdir dir=quot;${classes.dir}quot;/>
 <javac srcdir=quot;${src.dir}quot; destdir=quot;${classes.dir}quot; classpathref=quot;classpathquot;/>
</target>
Ant Targets
    Name



    Description



    Dependencies



    Conditionals (if, unless)



    <antcall> task

Ant Tasks
    Core tasks



    Optional tasks



    Custom tasks



        Third party
    


        Write your own
    
Selected Core Tasks
Ant AntCall Apply Basename BuildNumber Checksum
Chmod Concat Condition Copy Cvs Delete DependSet
Dirname Ear Echo EchoXML Exec Fail Filter FixCRLF Get
Import Input Jar Java Javac Javadoc Length LoadFile
LoadProperties LoadResource MakeURL Mail MacroDef
Manifest ManifestClassPath Mkdir Move Nice Parallel
Patch PathConvert PreSetDef Property Record Replace
ResourceCount Retry Rmic Sequential SignJar Sleep Sql
Subant Sync Tar Taskdef Tempfile Touch Truncate TStamp
Typedef Unjar Untar Unwar Unzip Uptodate Waitfor
WhichResource War XmlProperty XSLT Zip
Ant Multi-Project Builds
    Option 1 – Master build.xml



    Option 2 – Cascading build.xml's

Ant Scripting
    <macrodef> task



    <script> task

Ivy for Dependencies
build.xml
<project xmlns:ivy=quot;antlib:org.apache.ivy.antquot;
    name=quot;hello-ivyquot; default=quot;runquot;>
  <target name=quot;resolvequot;>
    <ivy:retrieve />
  </target>
</project>
Ivy for Dependencies
ivy.xml
<ivy-module version=quot;2.0quot;>
  <info organisation=quot;apachequot; module=quot;hello-ivyquot;/>
  <dependencies>
    <dependency org=quot;commons-langquot;
          name=quot;commons-langquot; rev=quot;2.0quot;/>
    <dependency org=quot;commons-cliquot;
          name=quot;commons-cliquot; rev=quot;1.0quot;/>
  </dependencies>
</ivy-module>
Ivy Repositories
    Maven artifact repositories



    Build your own

Ivy Reports
Ant Ecosystem
    IDE plugins



    Custom tasks

More Ant
Ant
 http://ant.apache.org/

Core tasks
 http://ant.apache.org/manual/coretasklist.html

External tools
 http://ant.apache.org/external.html

IVY
 http://ant.apache.org/ivy/
Maven
    Project and artifact-based build



    platform
    Uses repositories to manage



    artifacts and third party libraries
    Customized by modifying the



    behavior of the life-cycle via plugins.
Maven
Maven Artifacts
    Output of the build process



    JARs, WARs, EARs, zip files



    Stored in repositories



    Published and consumed by Maven



    One per project

Maven Dependencies
    Items needed during build process



    Managed as artifacts and metadata



    within remote repositories
    Usually created and published by



    other Maven builds
        Though not necessarily
    
Maven Dependencies
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.2</version>
    <scope>test</scope>
</dependency>
Maven Directory Structure
    pom.xml



    src/



    target/

Maven Directory Structure
    src



        main
    


          com/example/app/App.java
        


        test
    


            com/example/app/AppTest.java
        
Maven Directory Structure
    target




        classes/
    


        generated-classes/
    


        site/
    


        surefire-reports/
    


        test-classes/
    


        webdemo-1.0-SNAPSHOT.war
    
Maven Project Object Model
    “POM”



    Fundamental unit of work in Maven



    Build components inherit from best



    practices and common base
Maven Build Life-Cycle
    Consistent pattern



    Portable process knowledge



    Modify build with plugins



        Extensible in decoupled way
    



    Large number of phases, not all



    required
        Compile, test, package, install, deploy
    
Default Lifecycle Phases
    validate, initialize



    generate-sources, process-sources



    generate-resources, process-resources



    compile, process-classes



    generate-test-sources, process-test-sources



    generate-test-resources, process-test-resources



    test-compile, process-test-classes



    test



    prepare-package, package



    pre-integration-test, integration-test, post-integration-test



    verify, install, deploy

Site Lifecycle Phases
    Pre-site: executes processes



    Site: generates documentation



    Post-site: executes processes



    Site-deploy: copies files

Clean Lifecycle Phases
    Pre-clean: executes processes



    Clean: removes files



    Post-clean: executes processes

Phases have Goals
generate-resources ear:generateApplicationXml

process-resources   resources:resources

package             ear:ear

install             install:install

deploy              deploy:deploy
Maven Settings
    Two setting files



    Installation settings:



        conf/settings.xml in install directory
    



    User settings: ~/.m2/settings.xml



        C:Usersusername on Windows Vista
    


        C:Documents and Settingsusername on XP
    
Maven Settings
Separate installation and user settings
      User settings are things you don't share
  


          server usernames and passwords, local paths, etc.
      



      Installation settings are things that should
  


      be the same on all Maven installations
          can distribute various ways: check out Maven install
      


          from SCM, provide a re-bundled Maven, etc.
Maven Archetypes
    POJO jar



    Web applications



        AppFuse, Wicket, MyFaces, etc
    



    Groovy

Maven Archetypes
    mvn archetype:generate



    Application structure



    Code generation



    Plugin



    Distributed in repositories

Maven Resources
    Accessed by code at runtime



    Not required for compilation



    Packaged within the artifact



    Can be filtered with custom values

Maven Plugins
    Reusable pieces of build functionality



    Perform a clearly defined task based on a set of



    input configuration
    Maven takes responsibility for orchestrating their



    execution
    Primarily written in Java, but can be written in a



    number of scripting languages
    Are also stored and downloaded from repositories

Maven Repositories
    Repositories are a storage location for artifacts



    Maven has two types:



        Remote repository - repository accessible over HTTP, FTP, filesystem, etc that
    

        contains artifacts to consume and as a place to publish build artifacts
        Local repository - a cache of artifacts on your machine, downloaded from
    

        several remote repositories
    Maven is pre-configured to use the Central Repository for


    dependencies
    A large collection of open source and re-distributable artifacts,


    primarily for Java
    Can establish and manage your own remote repositories



    Can be used by build systems other than Maven

Repository Servers
    Archiva



    Artifactory



    Nexus

Archiva
    Helps to manage Maven repositories



    Control your environment for your



    team
    Can be run personally for offline



    cache
Archiva
    A repository management server



        manages Maven remote repositories and the artifacts inside them
    


    Used by a group or team for an “internal” remote repository



        deploy your own build artifacts
    


        control content from external sources
    


        on demand downloading of artifacts
    


        CI server companion
    


    Can be used as a personal server



        make it easier to clean your local repository without downloading remotely again
    


        must be careful about introducing build inconsistencies localized to your
    

        environment, however
Installing Archiva
    Two choices



        Existing servlet container or application server
    


        Standalone
    


        pre-configured instance of Jetty 6, Java Service Wrapper, Apache Derby
    



    Configuration files



        APP_BASE/conf/jetty.xml - server port, outgoing mail server and databases
    


            standalone only, configure using container settings for others
        



        APP_BASE/conf/archiva.xml - maintained by the application
    


            applies to both choices
        



    Two databases – users and repository statistics



    When using standalone, recommend a separate conf directory



        set ARCHIVA_BASE environment variable to point to a copy of the conf directory
    


        makes upgrading easier
    
Configuring Maven For Archiva
    There are a number of alternatives for configuring Maven to use a repository


    manager:
        add to the POM
    


        used in addition to central, but always checked first
    


        add to Maven settings
    


        as above, but applies to all projects
    


        override or mirror central
    


        never use the central repository, everything else the same
    


        override or mirror all repositories given
    


    Could add the repositories to the POM


        what if the parent POM is in the repository, not the check out?
    


        use the POM if users must build using that repository without configuring settings
    


    Use Maven settings instead


        generally prefer the mirror all repositories
    
Maven
    Archetypes



    Artifacts



    POM – Project Object Model



    Dependencies



    Directory structure



    Plugins (testing, reporting, deploying, etc)



    Repositories

Maven Ecosystem
    IDE support



    Artifact repositories



    Plugins



    Continuous integration

Maven Companies
Maven Links
Maven
 http://maven.apache.org/

Archiva
 http://archiva.apache.org/

Artifacts
 http://mvnrepository.com/

Free Books
 http://www.exist.com/better-build-maven/
 http://www.sonatype.com/book
Credits
Special thanks to Carlos Sanchez and Brett Porter
for their inputs and material from their training slides
Thanks!
David Noble
dnoble@g2ix.com
www.dnoble.org

Contenu connexe

Tendances (20)

Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
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
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Development Tools - Maven
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven
Maven Maven
Maven
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Learning Maven by Example
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
 
Maven
MavenMaven
Maven
 
Maven tutorial for beginners
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
 
Maven 2 Introduction
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 
Maven
MavenMaven
Maven
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 

En vedette

Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011Ching Yi Chan
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basicsWalid Ashraf
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentDan Stine
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparisonManav Prasad
 
Apache Ant
Apache AntApache Ant
Apache AntAli Bahu
 
Apache ANT vs Apache Maven
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache MavenMudit Gupta
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツールEnpel
 

En vedette (20)

Java Build Tool course in 2011
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011
 
docker installation and basics
docker installation and basicsdocker installation and basics
docker installation and basics
 
Docker Basics
Docker BasicsDocker Basics
Docker Basics
 
Manen Ant SVN
Manen Ant SVNManen Ant SVN
Manen Ant SVN
 
Apache ant
Apache antApache ant
Apache ant
 
Docker Basics
Docker BasicsDocker Basics
Docker Basics
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Tomcat tutorail
Tomcat tutorailTomcat tutorail
Tomcat tutorail
 
Releasing Projects Using Maven
Releasing Projects Using MavenReleasing Projects Using Maven
Releasing Projects Using Maven
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
 
ANT
ANTANT
ANT
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Building java projects with maven
Building java projects with mavenBuilding java projects with maven
Building java projects with maven
 
Apache ANT vs Apache Maven
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache Maven
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
 
XPATH
XPATHXPATH
XPATH
 

Similaire à Java Builds with Maven and Ant

maven
mavenmaven
mavenakd11
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsPetr Jiricka
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
 
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
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialRaghavan Mohan
 
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java AppsWebinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java AppsCodefresh
 
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
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedorawolfc71
 
JSUG - Maven by Michael Greifeneder
JSUG - Maven by Michael GreifenederJSUG - Maven by Michael Greifeneder
JSUG - Maven by Michael GreifenederChristoph Pickl
 
20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache MavenArnaud Héritier
 
Java Build Tools
Java Build ToolsJava Build Tools
Java Build Tools­Avishek A
 
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
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 

Similaire à Java Builds with Maven and Ant (20)

maven
mavenmaven
maven
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.jsExtending Build to the Client: A Maven User's Guide to Grunt.js
Extending Build to the Client: A Maven User's Guide to Grunt.js
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
 
Maven2交流
Maven2交流Maven2交流
Maven2交流
 
Jenkins advance topic
Jenkins advance topicJenkins advance topic
Jenkins advance topic
 
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
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java AppsWebinar: Creating an Effective Docker Build Pipeline for Java Apps
Webinar: Creating an Effective Docker Build Pipeline for Java Apps
 
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
 
Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
JSUG - Maven by Michael Greifeneder
JSUG - Maven by Michael GreifenederJSUG - Maven by Michael Greifeneder
JSUG - Maven by Michael Greifeneder
 
20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven
 
Java Build Tools
Java Build ToolsJava Build Tools
Java Build Tools
 
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
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
Mavenppt
MavenpptMavenppt
Mavenppt
 

Plus de David Noble

Scratch project ideas
Scratch project ideasScratch project ideas
Scratch project ideasDavid Noble
 
Open Source BPM in Java
Open Source BPM in JavaOpen Source BPM in Java
Open Source BPM in JavaDavid Noble
 
Mobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science FictionMobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science FictionDavid Noble
 
Cloud Computing - a conversation
Cloud Computing - a conversationCloud Computing - a conversation
Cloud Computing - a conversationDavid Noble
 
Return of the Command Line: New Text Interfaces
Return of the Command Line: New Text InterfacesReturn of the Command Line: New Text Interfaces
Return of the Command Line: New Text InterfacesDavid Noble
 
Java Code Generation for Productivity
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for ProductivityDavid Noble
 
Salesforce and Skype
Salesforce and SkypeSalesforce and Skype
Salesforce and SkypeDavid Noble
 
Salesforce and Google Calendar
Salesforce and Google CalendarSalesforce and Google Calendar
Salesforce and Google CalendarDavid Noble
 

Plus de David Noble (10)

Scratch project ideas
Scratch project ideasScratch project ideas
Scratch project ideas
 
Open Source BPM in Java
Open Source BPM in JavaOpen Source BPM in Java
Open Source BPM in Java
 
Mobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science FictionMobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science Fiction
 
Cloud Computing - a conversation
Cloud Computing - a conversationCloud Computing - a conversation
Cloud Computing - a conversation
 
Return of the Command Line: New Text Interfaces
Return of the Command Line: New Text InterfacesReturn of the Command Line: New Text Interfaces
Return of the Command Line: New Text Interfaces
 
Java Code Generation for Productivity
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for Productivity
 
Salesforce and Skype
Salesforce and SkypeSalesforce and Skype
Salesforce and Skype
 
Salesforce and Google Calendar
Salesforce and Google CalendarSalesforce and Google Calendar
Salesforce and Google Calendar
 
Files From Mars
Files From MarsFiles From Mars
Files From Mars
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 

Dernier

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 

Dernier (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 

Java Builds with Maven and Ant

  • 1. Pasadena Java Users Group pasadenajug.org Java Builds with Ant & Maven Feb 23, 2009 David Noble dnoble@g2ix.com
  • 2. About Me David Noble Sr Solutions Architect Exist Global / G2iX
  • 3. About You Ant users? Ivy?  Maven users?  Continuous integration? 
  • 4. Build Tool Collect inputs  Process inputs  Generate final outputs 
  • 5. Build Tool - Inputs Source code  Java, SQL  Resources  Properties, XML  Dependencies  Libraries, components, frameworks 
  • 6. Build Tool - Processing Compile  Run tests  Copy files  Replace keywords  Package  Install / deploy 
  • 7. Build Tool - Outputs JAR / WAR / EAR files  Zip files  Reports 
  • 8. Ant Maven Procedural Declarative 1. Set path 1. Define name & version 2. Compile jars 2. Define as WAR project 3. Run unit tests 3. Specify dependencies 4. Create reports 4. Specify unit test plugin 5. Copy files 6. Assemble WAR
  • 9. Ant “make for java”  Properties, paths, and filesets  Targets  Target dependencies  Tasks 
  • 10. Ant Installation Download  Unzip  Add to PATH  Set ANT_HOME env variable  Extend by adding jars to lib/  Customize by modifying XSL in etc/ 
  • 11. Ant Project Definition build.xml Project name  Property variables  Paths  Tasks  Targets 
  • 12. Ant Properties <property name=quot;lib.dirquot; value=quot;libquot;/> From command line  In build.xml  From external XML  From external property files  From environment 
  • 13. Ant Paths <path id=quot;classpathquot;> <fileset dir=quot;${lib.dir}quot; includes=quot;**/*.jarquot;/> </path> <target name=quot;compilequot;> <mkdir dir=quot;${classes.dir}quot;/> <javac srcdir=quot;${src.dir}quot; destdir=quot;${classes.dir}quot; classpathref=quot;classpathquot;/> </target>
  • 14. Ant Targets Name  Description  Dependencies  Conditionals (if, unless)  <antcall> task 
  • 15. Ant Tasks Core tasks  Optional tasks  Custom tasks  Third party  Write your own 
  • 16. Selected Core Tasks Ant AntCall Apply Basename BuildNumber Checksum Chmod Concat Condition Copy Cvs Delete DependSet Dirname Ear Echo EchoXML Exec Fail Filter FixCRLF Get Import Input Jar Java Javac Javadoc Length LoadFile LoadProperties LoadResource MakeURL Mail MacroDef Manifest ManifestClassPath Mkdir Move Nice Parallel Patch PathConvert PreSetDef Property Record Replace ResourceCount Retry Rmic Sequential SignJar Sleep Sql Subant Sync Tar Taskdef Tempfile Touch Truncate TStamp Typedef Unjar Untar Unwar Unzip Uptodate Waitfor WhichResource War XmlProperty XSLT Zip
  • 17. Ant Multi-Project Builds Option 1 – Master build.xml  Option 2 – Cascading build.xml's 
  • 18. Ant Scripting <macrodef> task  <script> task 
  • 19. Ivy for Dependencies build.xml <project xmlns:ivy=quot;antlib:org.apache.ivy.antquot; name=quot;hello-ivyquot; default=quot;runquot;> <target name=quot;resolvequot;> <ivy:retrieve /> </target> </project>
  • 20. Ivy for Dependencies ivy.xml <ivy-module version=quot;2.0quot;> <info organisation=quot;apachequot; module=quot;hello-ivyquot;/> <dependencies> <dependency org=quot;commons-langquot; name=quot;commons-langquot; rev=quot;2.0quot;/> <dependency org=quot;commons-cliquot; name=quot;commons-cliquot; rev=quot;1.0quot;/> </dependencies> </ivy-module>
  • 21. Ivy Repositories Maven artifact repositories  Build your own 
  • 23. Ant Ecosystem IDE plugins  Custom tasks 
  • 24. More Ant Ant http://ant.apache.org/ Core tasks http://ant.apache.org/manual/coretasklist.html External tools http://ant.apache.org/external.html IVY http://ant.apache.org/ivy/
  • 25. Maven Project and artifact-based build  platform Uses repositories to manage  artifacts and third party libraries Customized by modifying the  behavior of the life-cycle via plugins.
  • 26. Maven
  • 27. Maven Artifacts Output of the build process  JARs, WARs, EARs, zip files  Stored in repositories  Published and consumed by Maven  One per project 
  • 28. Maven Dependencies Items needed during build process  Managed as artifacts and metadata  within remote repositories Usually created and published by  other Maven builds Though not necessarily 
  • 29. Maven Dependencies <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.2</version> <scope>test</scope> </dependency>
  • 30. Maven Directory Structure pom.xml  src/  target/ 
  • 31. Maven Directory Structure src  main  com/example/app/App.java  test  com/example/app/AppTest.java 
  • 32. Maven Directory Structure target  classes/  generated-classes/  site/  surefire-reports/  test-classes/  webdemo-1.0-SNAPSHOT.war 
  • 33. Maven Project Object Model “POM”  Fundamental unit of work in Maven  Build components inherit from best  practices and common base
  • 34. Maven Build Life-Cycle Consistent pattern  Portable process knowledge  Modify build with plugins  Extensible in decoupled way  Large number of phases, not all  required Compile, test, package, install, deploy 
  • 35. Default Lifecycle Phases validate, initialize  generate-sources, process-sources  generate-resources, process-resources  compile, process-classes  generate-test-sources, process-test-sources  generate-test-resources, process-test-resources  test-compile, process-test-classes  test  prepare-package, package  pre-integration-test, integration-test, post-integration-test  verify, install, deploy 
  • 36. Site Lifecycle Phases Pre-site: executes processes  Site: generates documentation  Post-site: executes processes  Site-deploy: copies files 
  • 37. Clean Lifecycle Phases Pre-clean: executes processes  Clean: removes files  Post-clean: executes processes 
  • 38. Phases have Goals generate-resources ear:generateApplicationXml process-resources resources:resources package ear:ear install install:install deploy deploy:deploy
  • 39. Maven Settings Two setting files  Installation settings:  conf/settings.xml in install directory  User settings: ~/.m2/settings.xml  C:Usersusername on Windows Vista  C:Documents and Settingsusername on XP 
  • 40. Maven Settings Separate installation and user settings User settings are things you don't share  server usernames and passwords, local paths, etc.  Installation settings are things that should  be the same on all Maven installations can distribute various ways: check out Maven install  from SCM, provide a re-bundled Maven, etc.
  • 41. Maven Archetypes POJO jar  Web applications  AppFuse, Wicket, MyFaces, etc  Groovy 
  • 42. Maven Archetypes mvn archetype:generate  Application structure  Code generation  Plugin  Distributed in repositories 
  • 43. Maven Resources Accessed by code at runtime  Not required for compilation  Packaged within the artifact  Can be filtered with custom values 
  • 44. Maven Plugins Reusable pieces of build functionality  Perform a clearly defined task based on a set of  input configuration Maven takes responsibility for orchestrating their  execution Primarily written in Java, but can be written in a  number of scripting languages Are also stored and downloaded from repositories 
  • 45. Maven Repositories Repositories are a storage location for artifacts  Maven has two types:  Remote repository - repository accessible over HTTP, FTP, filesystem, etc that  contains artifacts to consume and as a place to publish build artifacts Local repository - a cache of artifacts on your machine, downloaded from  several remote repositories Maven is pre-configured to use the Central Repository for  dependencies A large collection of open source and re-distributable artifacts,  primarily for Java Can establish and manage your own remote repositories  Can be used by build systems other than Maven 
  • 46. Repository Servers Archiva  Artifactory  Nexus 
  • 47. Archiva Helps to manage Maven repositories  Control your environment for your  team Can be run personally for offline  cache
  • 48. Archiva A repository management server  manages Maven remote repositories and the artifacts inside them  Used by a group or team for an “internal” remote repository  deploy your own build artifacts  control content from external sources  on demand downloading of artifacts  CI server companion  Can be used as a personal server  make it easier to clean your local repository without downloading remotely again  must be careful about introducing build inconsistencies localized to your  environment, however
  • 49. Installing Archiva Two choices  Existing servlet container or application server  Standalone  pre-configured instance of Jetty 6, Java Service Wrapper, Apache Derby  Configuration files  APP_BASE/conf/jetty.xml - server port, outgoing mail server and databases  standalone only, configure using container settings for others  APP_BASE/conf/archiva.xml - maintained by the application  applies to both choices  Two databases – users and repository statistics  When using standalone, recommend a separate conf directory  set ARCHIVA_BASE environment variable to point to a copy of the conf directory  makes upgrading easier 
  • 50. Configuring Maven For Archiva There are a number of alternatives for configuring Maven to use a repository  manager: add to the POM  used in addition to central, but always checked first  add to Maven settings  as above, but applies to all projects  override or mirror central  never use the central repository, everything else the same  override or mirror all repositories given  Could add the repositories to the POM  what if the parent POM is in the repository, not the check out?  use the POM if users must build using that repository without configuring settings  Use Maven settings instead  generally prefer the mirror all repositories 
  • 51. Maven Archetypes  Artifacts  POM – Project Object Model  Dependencies  Directory structure  Plugins (testing, reporting, deploying, etc)  Repositories 
  • 52. Maven Ecosystem IDE support  Artifact repositories  Plugins  Continuous integration 
  • 54. Maven Links Maven http://maven.apache.org/ Archiva http://archiva.apache.org/ Artifacts http://mvnrepository.com/ Free Books http://www.exist.com/better-build-maven/ http://www.sonatype.com/book
  • 55. Credits Special thanks to Carlos Sanchez and Brett Porter for their inputs and material from their training slides