Java Builds with Maven and Ant

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
1 de 56

Recomendados

Maven 2 features por
Maven 2 featuresMaven 2 features
Maven 2 featuresAngel Ruiz
4.4K visualizações33 slides
Using Maven 2 por
Using Maven 2Using Maven 2
Using Maven 2andyhot
2.8K visualizações15 slides
An Introduction to Maven por
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
13.9K visualizações40 slides
Apache maven 2 overview por
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overviewReturn on Intelligence
1.8K visualizações37 slides
Maven Introduction por
Maven IntroductionMaven Introduction
Maven IntroductionSandeep Chawla
21.1K visualizações31 slides
Maven tutorial por
Maven tutorialMaven tutorial
Maven tutorialJames Cellini
2.1K visualizações91 slides

Mais conteúdo relacionado

Mais procurados

Maven 3 Overview por
Maven 3  OverviewMaven 3  Overview
Maven 3 OverviewMike Ensor
2.7K visualizações22 slides
Hands On with Maven por
Hands On with MavenHands On with Maven
Hands On with MavenSid Anand
6.1K visualizações29 slides
Log management (elk) for spring boot application por
Log management (elk) for spring boot applicationLog management (elk) for spring boot application
Log management (elk) for spring boot applicationVadym Lotar
876 visualizações5 slides
An Introduction to Maven Part 1 por
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
899 visualizações23 slides
Demystifying Maven por
Demystifying MavenDemystifying Maven
Demystifying MavenMike Desjardins
4.9K visualizações88 slides
Development Tools - Maven por
Development Tools - MavenDevelopment Tools - Maven
Development Tools - MavenBert Koorengevel
477 visualizações57 slides

Mais procurados(20)

Maven 3 Overview por Mike Ensor
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor2.7K visualizações
Hands On with Maven por Sid Anand
Hands On with MavenHands On with Maven
Hands On with Maven
Sid Anand6.1K visualizações
Log management (elk) for spring boot application por Vadym Lotar
Log management (elk) for spring boot applicationLog management (elk) for spring boot application
Log management (elk) for spring boot application
Vadym Lotar876 visualizações
An Introduction to Maven Part 1 por MD Sayem Ahmed
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
MD Sayem Ahmed899 visualizações
Demystifying Maven por Mike Desjardins
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins4.9K visualizações
Development Tools - Maven por Bert Koorengevel
Development Tools - MavenDevelopment Tools - Maven
Development Tools - Maven
Bert Koorengevel477 visualizações
Apache Maven por Rahul Tanwani
Apache MavenApache Maven
Apache Maven
Rahul Tanwani2.1K visualizações
Introduction to Maven por Mindfire Solutions
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions955 visualizações
Maven por Khan625
Maven Maven
Maven
Khan625905 visualizações
Maven ppt por natashasweety7
Maven pptMaven ppt
Maven ppt
natashasweety74.6K visualizações
Maven Presentation - SureFire vs FailSafe por Holasz Kati
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
Holasz Kati1.4K visualizações
An introduction to Maven por Joao Pereira
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira7.8K visualizações
Learning Maven by Example por Hsi-Kai Wang
Learning Maven by ExampleLearning Maven by Example
Learning Maven by Example
Hsi-Kai Wang1.6K visualizações
Maven tutorial for beginners por inTwentyEight Minutes
Maven tutorial for beginnersMaven tutorial for beginners
Maven tutorial for beginners
inTwentyEight Minutes307 visualizações
Maven 2 Introduction por Valentin Jacquemin
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
Valentin Jacquemin2.5K visualizações
Introduction to Maven por Onkar Deshpande
Introduction to MavenIntroduction to Maven
Introduction to Maven
Onkar Deshpande3.4K visualizações
Apache Maven In 10 Slides por Robert Burrell Donkin
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
Robert Burrell Donkin5.7K visualizações
Maven por Chris Roeder
MavenMaven
Maven
Chris Roeder2.3K visualizações
Introduction to maven por Manos Georgopoulos
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos1.2K visualizações

Destaque

Java Build Tool course in 2011 por
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011Ching Yi Chan
1.2K visualizações112 slides
docker installation and basics por
docker installation and basicsdocker installation and basics
docker installation and basicsWalid Ashraf
839 visualizações21 slides
Docker Basics por
Docker BasicsDocker Basics
Docker BasicsEueung Mulyana
2.6K visualizações36 slides
Manen Ant SVN por
Manen Ant SVNManen Ant SVN
Manen Ant SVNSriskandarajah Suhothayan
2K visualizações24 slides
Apache ant por
Apache antApache ant
Apache antYuriy Galavay
4.8K visualizações28 slides
Docker Basics por
Docker BasicsDocker Basics
Docker BasicsDuckDuckGo
1.1K visualizações33 slides

Destaque(20)

Java Build Tool course in 2011 por Ching Yi Chan
Java Build Tool course in 2011Java Build Tool course in 2011
Java Build Tool course in 2011
Ching Yi Chan1.2K visualizações
docker installation and basics por Walid Ashraf
docker installation and basicsdocker installation and basics
docker installation and basics
Walid Ashraf839 visualizações
Docker Basics por Eueung Mulyana
Docker BasicsDocker Basics
Docker Basics
Eueung Mulyana2.6K visualizações
Apache ant por Yuriy Galavay
Apache antApache ant
Apache ant
Yuriy Galavay4.8K visualizações
Docker Basics por DuckDuckGo
Docker BasicsDocker Basics
Docker Basics
DuckDuckGo1.1K visualizações
Jenkins and Chef: Infrastructure CI and Automated Deployment por Dan Stine
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
Dan Stine56.2K visualizações
Docker by Example - Basics por Ganesh Samarthyam
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
Ganesh Samarthyam20.1K visualizações
Tomcat tutorail por Supratim Ray
Tomcat tutorailTomcat tutorail
Tomcat tutorail
Supratim Ray489 visualizações
Java build tool_comparison por Manav Prasad
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
Manav Prasad338 visualizações
ANT por guestd845f0
ANTANT
ANT
guestd845f0582 visualizações
Introduction to Apache Ant por Muhammad Hafiz Hasan
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
Muhammad Hafiz Hasan783 visualizações
Apache Ant por Ali Bahu
Apache AntApache Ant
Apache Ant
Ali Bahu547 visualizações
Apache Ant por hussulinux
Apache AntApache Ant
Apache Ant
hussulinux6K visualizações
Apache ANT vs Apache Maven por Mudit Gupta
Apache ANT vs Apache MavenApache ANT vs Apache Maven
Apache ANT vs Apache Maven
Mudit Gupta1.3K visualizações
Apache Ant por Rajesh Kumar
Apache AntApache Ant
Apache Ant
Rajesh Kumar3.3K visualizações
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール por Enpel
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(3)-フォルダ構造、マネージャツール
Enpel2.1K visualizações
XPATH por Sun Technlogies
XPATHXPATH
XPATH
Sun Technlogies738 visualizações

Similar a Java Builds with Maven and Ant

maven por
mavenmaven
mavenakd11
375 visualizações25 slides
Extending Build to the Client: A Maven User's Guide to Grunt.js por
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
2K visualizações30 slides
Using Maven2 por
Using Maven2Using Maven2
Using Maven2elliando dias
812 visualizações53 slides
Maven2交流 por
Maven2交流Maven2交流
Maven2交流ChangQi Lin
331 visualizações33 slides
Jenkins advance topic por
Jenkins advance topicJenkins advance topic
Jenkins advance topicGourav Varma
182 visualizações29 slides
Maven: Managing Software Projects for Repeatable Results por
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
707 visualizações21 slides

Similar a Java Builds with Maven and Ant(20)

maven por akd11
mavenmaven
maven
akd11375 visualizações
Extending Build to the Client: A Maven User's Guide to Grunt.js por Petr Jiricka
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
Petr Jiricka2K visualizações
Using Maven2 por elliando dias
Using Maven2Using Maven2
Using Maven2
elliando dias812 visualizações
Maven2交流 por ChangQi Lin
Maven2交流Maven2交流
Maven2交流
ChangQi Lin331 visualizações
Jenkins advance topic por Gourav Varma
Jenkins advance topicJenkins advance topic
Jenkins advance topic
Gourav Varma182 visualizações
Maven: Managing Software Projects for Repeatable Results por Steve Keener
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
Steve Keener707 visualizações
Liferay maven sdk por Mika Koivisto
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
Mika Koivisto3.2K visualizações
Java, Eclipse, Maven & JSF tutorial por Raghavan Mohan
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan2K visualizações
Webinar: Creating an Effective Docker Build Pipeline for Java Apps por Codefresh
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
Codefresh473 visualizações
Apache maven, a software project management tool por Renato Primavera
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
Renato Primavera1.6K visualizações
Building JBoss AS 7 for Fedora por wolfc71
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
wolfc71514 visualizações
Maven por Fabio Bonfante
MavenMaven
Maven
Fabio Bonfante829 visualizações
Maven por darshanvartak
MavenMaven
Maven
darshanvartak269 visualizações
JSUG - Maven by Michael Greifeneder por Christoph Pickl
JSUG - Maven by Michael GreifenederJSUG - Maven by Michael Greifeneder
JSUG - Maven by Michael Greifeneder
Christoph Pickl433 visualizações
20091112 - Mars Jug - Apache Maven por Arnaud Héritier
20091112 - Mars Jug - Apache Maven20091112 - Mars Jug - Apache Maven
20091112 - Mars Jug - Apache Maven
Arnaud Héritier1.7K visualizações
Java Build Tools por ­Avishek A
Java Build ToolsJava Build Tools
Java Build Tools
­Avishek A959 visualizações
Maven 2.0 - Improve your build patterns por elliando dias
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patterns
elliando dias1.5K visualizações
Buildr In Action @devoxx france 2012 por alexismidon
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
alexismidon2.4K visualizações
Mavenppt por Surekha Achanta
MavenpptMavenppt
Mavenppt
Surekha Achanta840 visualizações

Mais de David Noble

Scratch project ideas por
Scratch project ideasScratch project ideas
Scratch project ideasDavid Noble
38K visualizações17 slides
Open Source BPM in Java por
Open Source BPM in JavaOpen Source BPM in Java
Open Source BPM in JavaDavid Noble
14.8K visualizações21 slides
Mobile Devices: Superpowers and Science Fiction por
Mobile Devices: Superpowers and Science FictionMobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science FictionDavid Noble
982 visualizações19 slides
Cloud Computing - a conversation por
Cloud Computing - a conversationCloud Computing - a conversation
Cloud Computing - a conversationDavid Noble
540 visualizações7 slides
Return of the Command Line: New Text Interfaces por
Return of the Command Line: New Text InterfacesReturn of the Command Line: New Text Interfaces
Return of the Command Line: New Text InterfacesDavid Noble
1.9K visualizações36 slides
Java Code Generation for Productivity por
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for ProductivityDavid Noble
1.5K visualizações35 slides

Mais de David Noble(10)

Scratch project ideas por David Noble
Scratch project ideasScratch project ideas
Scratch project ideas
David Noble38K visualizações
Open Source BPM in Java por David Noble
Open Source BPM in JavaOpen Source BPM in Java
Open Source BPM in Java
David Noble14.8K visualizações
Mobile Devices: Superpowers and Science Fiction por David Noble
Mobile Devices: Superpowers and Science FictionMobile Devices: Superpowers and Science Fiction
Mobile Devices: Superpowers and Science Fiction
David Noble982 visualizações
Cloud Computing - a conversation por David Noble
Cloud Computing - a conversationCloud Computing - a conversation
Cloud Computing - a conversation
David Noble540 visualizações
Return of the Command Line: New Text Interfaces por David Noble
Return of the Command Line: New Text InterfacesReturn of the Command Line: New Text Interfaces
Return of the Command Line: New Text Interfaces
David Noble1.9K visualizações
Java Code Generation for Productivity por David Noble
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for Productivity
David Noble1.5K visualizações
Salesforce and Skype por David Noble
Salesforce and SkypeSalesforce and Skype
Salesforce and Skype
David Noble1.5K visualizações
Salesforce and Google Calendar por David Noble
Salesforce and Google CalendarSalesforce and Google Calendar
Salesforce and Google Calendar
David Noble1.7K visualizações
Files From Mars por David Noble
Files From MarsFiles From Mars
Files From Mars
David Noble2.7K visualizações
Testing In Java por David Noble
Testing In JavaTesting In Java
Testing In Java
David Noble29.8K visualizações

Último

SAP Automation Using Bar Code and FIORI.pdf por
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
19 visualizações38 slides
Combining Orchestration and Choreography for a Clean Architecture por
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean ArchitectureThomasHeinrichs1
68 visualizações24 slides
Melek BEN MAHMOUD.pdf por
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 visualizações1 slide
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... por
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...NUS-ISS
15 visualizações28 slides
RADIUS-Omnichannel Interaction System por
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction SystemRADIUS
14 visualizações21 slides
How the World's Leading Independent Automotive Distributor is Reinventing Its... por
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...NUS-ISS
15 visualizações25 slides

Último(20)

SAP Automation Using Bar Code and FIORI.pdf por Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Virendra Rai, PMP19 visualizações
Combining Orchestration and Choreography for a Clean Architecture por ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs168 visualizações
Melek BEN MAHMOUD.pdf por MelekBenMahmoud
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdf
MelekBenMahmoud14 visualizações
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... por NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS15 visualizações
RADIUS-Omnichannel Interaction System por RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS14 visualizações
How the World's Leading Independent Automotive Distributor is Reinventing Its... por NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 visualizações
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... por NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS28 visualizações
.conf Go 2023 - Data analysis as a routine por Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk90 visualizações
Perth MeetUp November 2023 por Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price12 visualizações
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze por NUS-ISS
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng TszeDigital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
Digital Product-Centric Enterprise and Enterprise Architecture - Tan Eng Tsze
NUS-ISS19 visualizações
STPI OctaNE CoE Brochure.pdf por madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 visualizações
Future of Learning - Yap Aye Wee.pdf por NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS38 visualizações
AI: mind, matter, meaning, metaphors, being, becoming, life values por Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
Twain Liu 刘秋艳34 visualizações
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... por NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 visualizações
Java Platform Approach 1.0 - Picnic Meetup por Rick Ossendrijver
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver25 visualizações
[2023] Putting the R! in R&D.pdf por Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 visualizações
Special_edition_innovator_2023.pdf por WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2214 visualizações
Report 2030 Digital Decade por Massimo Talia
Report 2030 Digital DecadeReport 2030 Digital Decade
Report 2030 Digital Decade
Massimo Talia13 visualizações
Web Dev - 1 PPT.pdf por gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet52 visualizações

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