MAVEN
INTELLIGENT PROJECTS
          Mert ÇALI!KAN
About Me
•   Mert ÇALIŞKAN

    •   Software Plumber :)
          SCJP certified bla bla..

•   Open Source Software advoca...
About You
                 +




 Gradle



    Java Developer Conference 2010
Agenda
 •   Maven is ?                         •   IDE Support
 •   Core Concepts                      •   How to increase...
MAVEN ?



Java Developer Conference 2010
Maven is...
•   A project management framework from ASF

•   Uniform build system

•   Making the build as easy as possibl...
Highlights
•   Convention over Configuration

•   Common Interfaces
      The time of build engineers is over
      Stop bu...
THE POM



Java Developer Conference 2010
The POM
•   It is what makes your project a maven project

•   An XML file

•   Not just for building the project
         ...
The POM
 http://tinyurl.com/maven-xsddoc




  Java Developer Conference 2010
The POM
<project ...>
    <parent />
    <groupId /> <artifactId /> <version />
    <packaging />
    <developers /> <cont...
Simplest POM
   <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.egjug.jdc2010</groupId>
      <artif...
How is that possible with 6 lines of XML?

Where do I define the source folders, test
folders and all other stuff ?




   ...
Super POM
•   Same analogy with java.lang.Object

•   ${M2_HOME}/lib/ maven-2.2.1-uber.jar!
    /org/apache/maven/project/...
BUILD
            LIFE CYCLE


Java Developer Conference 2010
Build Life Cycle
•   Process for building and distributing an artifact is clearly
    defined

•   3 built-in Life Cycles
 ...
validate
                                     default
                   compile

                                       t...
default
    validate
                                          mvn <phase>
                                       mvn <pha...
DEPENDENCY
            MECHANISM


Java Developer Conference 2010
Dependency Mechanism
•   Gimme the Coordinates ! (GAV factor)
       <dependency>
         <groupId>junit</groupId>
      ...
$ mvn dependency:tree
[INFO] net:eniyiyemek:war:1.0-SNAPSHOT
[INFO] +- org.jboss.seam:jboss-seam:jar:2.2.0.GA:compile
[INF...
$ mvn dependency:analyze
 Unused declared deps:
  [WARNING] Unused declared dependencies found:
  [WARNING] org.egjug.jdc2...
Scopes for Dependencies
                        compile
                                             provided
            ...
CTR   compile              default scope, compile scoped dependencies will be in classpath

                            si...
Versioning and Ranges
<major>.<minor>.<incremental> - <qualifier>

                        1.2.3 / 1.2.3-alpha-01

Be care...
SNAPSHOT qualifier
•   Active development version

•   Resolve from remote Repo:
     myjar-1.0.0-SNAPSHOT.jar
     applie...
How Maven
               Resolve
              Versions?

Java Developer Conference 2010
Compile
                                                 A : A : 1.0




 D : D : 1.0                               C : C ...
A : A : 1.0




 D : D : 1.0                               C : C : 1.0                 B : B : 1.0


          Which B wil...
Closest One
                                                 A : A : 1.0




 D : D : 1.0                               C ...
Which commons-logging?
                                                     A : A : 1.0




     D : D : 1.0              ...
The sequential first at the same distance
                                                  A : A : 1.0




  D : D : 1.0 ...
A : A : 1.0




        D : D : 1.0              C : C : 1.0      B : B : 1.0




   commons-logging
   commons-logging
  ...
IS PROJECT A GONNA WORK ?

                                 A : A : 1.0




        D : D : 1.0              C : C : 1.0  ...
A : A : 1.0




        D : D : 1.0              C : C : 1.0      B : B : 1.0




   commons-logging
   commons-logging
  ...
USE <dependencyManagement />
                                                 A : A : 1.0




 D : D : 1.0                ...
Managing Dependencies
    Managing Projects

Inheritance



                                    Aggregation



           ...
Inheritance
                               <project>
                                 <modelVersion>4.0.0</modelVersion>
p...
Inheritance <dependencyManagement />
                              <project>
                                <modelVersion...
Inheritance <dependencyManagement />
                            <project>
                              <modelVersion>4.0...
Aggregation
                  <<depends>>                    <<depends>>
ProjectA                          ProjectB       ...
Aggregation
                 modulesapp                                modulesapp:


<<module>>
                          ...
POM Bundles
    <project>
	    <modelVersion>4.0.0</modelVersion>
	    <groupId>org.egjug.jdc2010</groupId>
	    <artifact...
POM Bundles


	 <dependency>
	    <groupId>org.egjug.jdc2010</groupId>
	    <artifactId>commonspom</artifactId>
	    <vers...
REPOSITORIES



Java Developer Conference 2010
M2_REPO/javax/activation/activation/1.1/activation-1.1.jar
M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar
M2_REPO/asm/asm/3.1/a...
M2_REPO/javax/activation/activation/1.1/activation-1.1.jar
M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar
M2_REPO/asm/asm/3.1/a...
Repositories
•   Repositories are for managing build artifacts and
    dependencies

•   local or remote repositories

•  ...
Repositories
	   	   <repository>
	   	   	   <id>jboss-repo</id>
	   	   	   <name>The Release JBoss maven repo</name>
	 ...
Create Your own Repo
•   Go Corporate !

•   Deploy and share your projects artifacts
         across your team

•   Cache...
Sonatype Nexus
Nexus Repository Manager
• Just a Web App, nice UI
• Upload artifacts via HTTP, RESTful
  style
• Indexing ...
Searching for Artifacts
• http://repository.apache.org
• http://www.jarvana.com
• http://www.artifact-repository.org
• htt...
PLUGINS



Java Developer Conference 2010
Plugins
•   Plugin-oriented Architecture
       plugin for even compiling the code..

•   A maven artifact w/ descriptor (...
Plugins available @ maven
                                Packaging                          Integration
                 ...
ARCHETYPES



Java Developer Conference 2010
Archetypes
•   Templates for maven projects

•   Descriptor XML files + velocity templates

•   To create a maven project:
...
Archetype Catalogs
•   Descriptor file to share Archetypes globally.
       <?xml version="1.0" encoding="UTF-8"?>
       <...
Archetypes from Existing Project

  •   Use an existing project as a seed for archetype


       $ mvn archetype:create-fr...
IDE Support



Java Developer Conference 2010
Maven with IDEs
     •     Eclipse 3.5 Galileo
               Eclipse IAM (formerly Q4E)
               m2eclipse
        ...
m2eclipse

•   Eclipse plug-in from Sonatype
•   Checkout maven project from Source Control
•   Create new Project from Ar...
INCREASE
             YOUR
          MOJOTIVITY

Java Developer Conference 2010
Maven Help Plugin
mvn help:describe -Dplugin=<anygoal>

• Lists & describes the goals of the plugin
mvn help:system

• Lis...
Use Profiles
• Create profiles for : development, staging and production
<profile>
  <id>production</id>
  <build>
    <plu...
Property References
env.*
  environment variables exposed by OS or Shell
      ${env.JAVA_HOME}

project.*
  POM elements
...
Debugging Maven

• Output full error stacktrace
    mvn <anygoal> -e

• Output for debugging
    mvn <anygoal> -X

       ...
GOOD PRACTICES
• If you are starting from scratch, start with MAVEN..!
• A Repository Manager is a MUST
    Have a Corpora...
GOOD PRACTICES
• Make it so that you can,
    Release early, Release Often
          - Quick, easy and reproducible releas...
Online Resources
http://www.sonatype.com/book
   Maven: The Complete Reference
   Maven By Example
   m2eclipse Book
   Ne...
Questions


Java Developer Conference 2010
Thank you

   Sponsored by:
Upcoming SlideShare
Loading in …5
×

Jdc 2010 - Maven, Intelligent Projects

3,118 views

Published on

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,118
On SlideShare
0
From Embeds
0
Number of Embeds
46
Actions
Shares
0
Downloads
231
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Jdc 2010 - Maven, Intelligent Projects

  1. 1. MAVEN INTELLIGENT PROJECTS Mert ÇALI!KAN
  2. 2. About Me • Mert ÇALIŞKAN • Software Plumber :) SCJP certified bla bla.. • Open Source Software advocate. Involved in numerous OSS projects like PrimeFaces, mesir ... • Apache Software Foundation member OpenLogic Expert Community member http://www.jroller.com/mert http://www.twitter.com/mertcaliskan Java Developer Conference 2010
  3. 3. About You + Gradle Java Developer Conference 2010
  4. 4. Agenda • Maven is ? • IDE Support • Core Concepts • How to increase - The POM your MOJOtivity ? - Build Life Cycle - Dependency Mechanism - Repositories - Plugins • Archetypes Java Developer Conference 2010
  5. 5. MAVEN ? Java Developer Conference 2010
  6. 6. Maven is... • A project management framework from ASF • Uniform build system • Making the build as easy as possible • Comprehensive model for software projects • Versions: 1.x 2.x ( 2.0.x, 2.2.x(jdk1.5) ) 3.x 2.x projects & plugins are still supported completely rewritten - new artifact resolution system / dependency resolving algorithm. Better IDE support Java Developer Conference 2010
  7. 7. Highlights • Convention over Configuration • Common Interfaces The time of build engineers is over Stop building the build and focus on development ! • Dependency Management Public repositories • Plugin Architecture • Documentation Generate documentation, reports ... Java Developer Conference 2010
  8. 8. THE POM Java Developer Conference 2010
  9. 9. The POM • It is what makes your project a maven project • An XML file • Not just for building the project project’s relationship, list of team members, license, SCM and etc. • Not only for Java projects build FLEX code with appropriate plugins build Microsoft binaries from C# code Java Developer Conference 2010
  10. 10. The POM http://tinyurl.com/maven-xsddoc Java Developer Conference 2010
  11. 11. The POM <project ...> <parent /> <groupId /> <artifactId /> <version /> <packaging /> <developers /> <contributors /> <scm>... </scm> <build> <plugins>....</plugins> </build> <dependencies>....</dependencies> <repositories>....</repositories> <pluginRepositories>... </pluginRepositories> <profiles>...</profiles> <reporting>... </reporting> </project> Java Developer Conference 2010
  12. 12. Simplest POM <project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>my-app</artifactId> <version>1.0.0</version> </project> } compile code run tests $ mvn install package as jar deploy to local repo Java Developer Conference 2010
  13. 13. How is that possible with 6 lines of XML? Where do I define the source folders, test folders and all other stuff ? Java Developer Conference 2010
  14. 14. Super POM • Same analogy with java.lang.Object • ${M2_HOME}/lib/ maven-2.2.1-uber.jar! /org/apache/maven/project/pom-4.0.0.xml • Standard directory layout • Locks versions of common plugins >= 2.0.9 • Repo def. for http://repo1.maven.org/maven2 • To see the merged POM: $!mvn help:effective-pom Java Developer Conference 2010
  15. 15. BUILD LIFE CYCLE Java Developer Conference 2010
  16. 16. Build Life Cycle • Process for building and distributing an artifact is clearly defined • 3 built-in Life Cycles default: handle project deployment clean: clean project files generated by a build site: generate project’s site doc. • Life Cycle consists of phases in specific order • Zero or more goals attached to each phase Java Developer Conference 2010
  17. 17. validate default compile test package integration-test verify install deploy Java Developer Conference 2010
  18. 18. default validate mvn <phase> mvn <phase:goal> compile mvn <phase> <phase:goal> mvn <phase:goal> <phase:goal> test package $ mvn integration-test integration-test validate verify compile install test deploy package integration-test Java Developer Conference 2010
  19. 19. DEPENDENCY MECHANISM Java Developer Conference 2010
  20. 20. Dependency Mechanism • Gimme the Coordinates ! (GAV factor) <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>compile</scope> </dependency> • Transitive Dependencies You can exclude what you don’t want or omit them all with <optional>false</optional> Java Developer Conference 2010
  21. 21. $ mvn dependency:tree [INFO] net:eniyiyemek:war:1.0-SNAPSHOT [INFO] +- org.jboss.seam:jboss-seam:jar:2.2.0.GA:compile [INFO] | +- xstream:xstream:jar:1.1.3:compile [INFO] | +- xpp3:xpp3_min:jar:1.1.3.4.O:compile [INFO] | - org.jboss.el:jboss-el:jar:1.0_02.CR4:compile [INFO] +- org.jboss.seam:jboss-seam-ui:jar:2.2.0.GA:compile [INFO] | +- org.jboss.seam:jboss-seam:ejb:2.2.0.GA:compile [INFO] | +- org.jboss.seam:jboss-seam-jul:jar:2.2.0.GA:compile [INFO] | - commons-beanutils:commons-beanutils:jar:1.7.0:compile [INFO] +- org.jboss.seam:jboss-seam-mail:jar:2.2.0.GA:compile [INFO] +- javax.mail:mail:jar:1.4.1:compile [INFO] | - javax.activation:activation:jar:1.1:compile [INFO] +- quartz:quartz:jar:1.6.0:compile [INFO] +- commons-logging:commons-logging:jar:1.1.1:compile [INFO] +- javax.faces:jsf-api:jar:1.2_13:compile [INFO] +- javax.faces:jsf-impl:jar:1.2_13:compile [INFO] +- com.sun.facelets:jsf-facelets:jar:1.1.14:compile [INFO] +- jstl:jstl:jar:1.2:compile [INFO] +- org.primefaces:primefaces-stable:jar:1.0.0:compile [INFO] +- javax.transaction:jta:jar:1.1:compile [INFO] +- org.hibernate:hibernate-core:jar:3.5.0-Beta-2:compile [INFO] | +- antlr:antlr:jar:2.7.6:compile [INFO] | +- dom4j:dom4j:jar:1.6.1:compile [INFO] | - org.slf4j:slf4j-api:jar:1.5.8:compile [INFO] +- org.hibernate:hibernate-annotations:jar:3.5.0-Beta-2:compile [INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Beta1:compile [INFO] | +- org.hibernate.java-persistence:jpa-api:jar:2.0-cr-1:compile [INFO] | - hsqldb:hsqldb:jar:1.8.0.2:compile [INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.0-Beta-2:compile [INFO] | - cglib:cglib:jar:2.2:compile [INFO] | - asm:asm:jar:3.1:compile [INFO] +- org.hibernate:hibernate-validator-legacy:jar:4.0.2.GA:compile Java Developer Conference 2010
  22. 22. $ mvn dependency:analyze Unused declared deps: [WARNING] Unused declared dependencies found: [WARNING] org.egjug.jdc2010:projectB:jar:1.0:compile [WARNING] org.egjug.jdc2010:projectC:jar:1.0:compile Used undeclared deps: [WARNING] Used undeclared dependencies found: [WARNING] opensymphony:xwork:jar:2.0.0:compile Java Developer Conference 2010
  23. 23. Scopes for Dependencies compile provided runtime test system import CTR Classpaths Compile Test Runtime Java Developer Conference 2010
  24. 24. CTR compile default scope, compile scoped dependencies will be in classpath similar to the compile, artifact should be provided by CT provided JDK / container @ runtime TR runtime not needed for compilation but needed @ runtime T test only needed for test compilation & execution same as provided, but artifact should be provided CT system explicitly with <systemPath /> with maven 2.0.9...dependency to be replaced with --- import the dependencies in that POM's <dependencyManagement> section. Java Developer Conference 2010
  25. 25. Versioning and Ranges <major>.<minor>.<incremental> - <qualifier> 1.2.3 / 1.2.3-alpha-01 Be careful with string comparison, ordering at the qualifiers... 1.2.3-alpha-2 > 1.2.3-alpha-10 (, ) - Exclusive [, ] - Inclusive <version>[3.8,4.0)</version> Java Developer Conference 2010
  26. 26. SNAPSHOT qualifier • Active development version • Resolve from remote Repo: myjar-1.0.0-SNAPSHOT.jar applies pattern date . time - build# resolves to myjar-1.0.0-20100219.141012-1.jar Install to local Repo: 1.0.0-SNAPSHOT will be 1.0.0-SNAPSHOT Java Developer Conference 2010
  27. 27. How Maven Resolve Versions? Java Developer Conference 2010
  28. 28. Compile A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging commons-logging commons-logging B : B : 2.0 commons-logging commons-logging 1.0.4 1.1.1 1.0.1 commons-logging commons-logging 1.1.1 Java Developer Conference 2010 Dependency Graph
  29. 29. A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 Which B will Maven choose? commons-logging commons-logging commons-logging commons-logging B : B : 2.0 commons-logging commons-logging 1.0.4 1.1.1 1.0.1 commons-logging commons-logging 1.1.1 B : 2.0 ? Highest One? Java Developer Conference 2010
  30. 30. Closest One A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging commons-logging commons-logging B : B : 2.0 commons-logging commons-logging 1.0.4 1.1.1 1.0.1 commons-logging commons-logging 1.1.1 Java Developer Conference 2010
  31. 31. Which commons-logging? A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 ? commons-logging commons-logging 1.0.4 B : B : 2.0 commons-logging commons-logging 1.1.1 ? commons-logging commons-logging 1.0.1 ? ? commons-logging commons-logging 1.1.1 Java Developer Conference 2010
  32. 32. The sequential first at the same distance A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging commons-logging commons-logging B : B : 2.0 commons-logging commons-logging 1.0.4 1.1.1 1.0.1 commons-logging commons-logging 1.1.1 Java Developer Conference 2010
  33. 33. A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging 1.0.4 Dependency Graph Java Developer Conference 2010
  34. 34. IS PROJECT A GONNA WORK ? A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging 1.0.4 Dependency Graph Java Developer Conference 2010
  35. 35. A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging 1.0.4 Dependency Graph Java Developer Conference 2010
  36. 36. USE <dependencyManagement /> A : A : 1.0 D : D : 1.0 C : C : 1.0 B : B : 1.0 commons-logging commons-logging commons-logging commons-logging B : B : 2.0 commons-logging commons-logging 1.0.4 1.1.1 1.0.1 commons-logging commons-logging 1.1.1 Java Developer Conference 2010 Dependency Graph
  37. 37. Managing Dependencies Managing Projects Inheritance Aggregation POM Bundles Java Developer Conference 2010
  38. 38. Inheritance <project> <modelVersion>4.0.0</modelVersion> parentapp <parent> <groupId>org.egjug.jdc2010</groupId> <artifactId>parentapp</artifactId> <<extends>> <version>1.0.0</version> </parent> sampleapp <groupId>org.egjug.jdc2010</groupId> <artifactId>sampleapp</artifactId> <version>1.0.0</version> </project> Java Developer Conference 2010
  39. 39. Inheritance <dependencyManagement /> <project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>parentapp</artifactId> <packaging>pom</packaging> parentapp <version>1.0</version> <dependencyManagement> <<extends>> <dependencies> " <dependency> " <groupId>commongs-logging</groupId> sampleapp " <artifactId>commongs-logging</artifactId> " <version>1.1.1</version> </dependency> </dependencies> </dependencyManagement> </project> Java Developer Conference 2010
  40. 40. Inheritance <dependencyManagement /> <project> <modelVersion>4.0.0</modelVersion> " <parent> " " <groupId>org.egjug.jdc2010</groupId> parentapp " " <artifactId>parentapp</artifactId> " " <version>1.0</version> " </parent> <<extends>> <artifactId>sampleapp</artifactId> <dependencies> " <dependency> sampleapp " <groupId>commongs-logging</groupId> ! <artifactId>commongs-logging</artifactId> </dependency> will get version 1.1.1... </dependencies> </project> Java Developer Conference 2010
  41. 41. Aggregation <<depends>> <<depends>> ProjectA ProjectB ProjectC root $!cd ProjectC } projectC $ mvn compile projectC $ cd .. root $!cd ProjectB projectB $ mvn compile 8 lines !!! projectB $ cd .. root $!cd ProjectA projectA $ mvn compile Java Developer Conference 2010
  42. 42. Aggregation modulesapp modulesapp: <<module>> <project> <<module>> <modelVersion>4.0.0</modelVersion> <<module>> <groupId>org.egjug.jdc2010</groupId> <artifactId>modulesapp</artifactId> ProjectA ProjectB <packaging>pom</packaging> <version>1.0</version> <name>modulesapp</name> ProjectC <modules> <module>projectA</module> <module>projectB</module> <module>projectC</module> root $!cd modulesapp </modules> modulesapp $ mvn compile </project> Java Developer Conference 2010
  43. 43. POM Bundles <project> <modelVersion>4.0.0</modelVersion> <groupId>org.egjug.jdc2010</groupId> <artifactId>commonspom</artifactId> <packaging>pom</packaging> <version>1.0</version> <dependencies> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>2.0</version> </dependency> ..... </dependencies> </project> Java Developer Conference 2010
  44. 44. POM Bundles <dependency> <groupId>org.egjug.jdc2010</groupId> <artifactId>commonspom</artifactId> <version>1.0</version> <type>pom</type> </dependency> Java Developer Conference 2010
  45. 45. REPOSITORIES Java Developer Conference 2010
  46. 46. M2_REPO/javax/activation/activation/1.1/activation-1.1.jar M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar M2_REPO/asm/asm/3.1/asm-3.1.jar M2_REPO/cglib/cglib/2.2/cglib-2.2.jar M2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar M2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar M2_REPO/commons-lang/commons-lang/2.4/commons-lang-2.4.jar M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar M2_REPO/javax/el/el-api/1.0/el-api-1.0.jar M2_REPO/org/hibernate/hibernate-annotations/3.5.0-Beta-2/hibernate-annotations-3.5.0-Beta-2.jar M2_REPO/org/hibernate/hibernate-commons-annotations/3.2.0.Beta1/hibernate-commons-annotations-3.2.0.Beta1.jar M2_REPO/org/hibernate/hibernate-core/3.5.0-Beta-2/hibernate-core-3.5.0-Beta-2.jar M2_REPO/org/hibernate/hibernate-entitymanager/3.5.0-Beta-2/hibernate-entitymanager-3.5.0-Beta-2.jar M2_REPO/org/hibernate/hibernate-validator-legacy/4.0.2.GA/hibernate-validator-legacy-4.0.2.GA.jar M2_REPO/hsqldb/hsqldb/1.8.0.2/hsqldb-1.8.0.2.jar M2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jar M2_REPO/org/jboss/el/jboss-el/1.0_02.CR4/jboss-el-1.0_02.CR4.jar M2_REPO/org/jboss/seam/jboss-seam/2.2.0.GA/jboss-seam-2.2.0.GA.jar M2_REPO/org/jboss/seam/jboss-seam-jul/2.2.0.GA/jboss-seam-jul-2.2.0.GA.jar M2_REPO/org/jboss/seam/jboss-seam-mail/2.2.0.GA/jboss-seam-mail-2.2.0.GA.jar Stack M2_REPO/org/jboss/seam/jboss-seam-ui/2.2.0.GA/jboss-seam-ui-2.2.0.GA.jar M2_REPO/org/hibernate/java-persistence/jpa-api/2.0-cr-1/jpa-api-2.0-cr-1.jar M2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13.jar M2_REPO/com/sun/facelets/jsf-facelets/1.1.14/jsf-facelets-1.1.14.jar M2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13.jar M2_REPO/jstl/jstl/1.2/jstl-1.2.jar JSF M2_REPO/javax/transaction/jta/1.1/jta-1.1.jar M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar M2_REPO/javax/mail/mail/1.4.1/mail-1.4.1.jar PrimeFaces M2_REPO/postgresql/postgresql/8.4-701.jdbc3/postgresql-8.4-701.jdbc3.jar M2_REPO/org/primefaces/primefaces-stable/1.0.0/primefaces-stable-1.0.0.jar M2_REPO/quartz/quartz/1.6.0/quartz-1.6.0.jar Seam M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar M2_REPO/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar M2_REPO/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jar JPA M2_REPO/org/testng/testng/5.9/testng-5.9.jar M2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jar Java Developer Conference 2010 M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar Hibernate
  47. 47. M2_REPO/javax/activation/activation/1.1/activation-1.1.jar M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar M2_REPO/asm/asm/3.1/asm-3.1.jar M2_REPO/cglib/cglib/2.2/cglib-2.2.jar M2_REPO/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar M2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar M2_REPO/commons-lang/commons-lang/2.4/commons-lang-2.4.jar M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar M2_REPO/javax/el/el-api/1.0/el-api-1.0.jar M2_REPO/org/hibernate/hibernate-annotations/3.5.0-Beta-2/hibernate-annotations-3.5.0-Beta-2.jar 40 M2_REPO/org/hibernate/hibernate-commons-annotations/3.2.0.Beta1/hibernate-commons-annotations-3.2.0.Beta1.jar M2_REPO/org/hibernate/hibernate-core/3.5.0-Beta-2/hibernate-core-3.5.0-Beta-2.jar M2_REPO/org/hibernate/hibernate-entitymanager/3.5.0-Beta-2/hibernate-entitymanager-3.5.0-Beta-2.jar M2_REPO/org/hibernate/hibernate-validator-legacy/4.0.2.GA/hibernate-validator-legacy-4.0.2.GA.jar M2_REPO/hsqldb/hsqldb/1.8.0.2/hsqldb-1.8.0.2.jar M2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jar M2_REPO/org/jboss/el/jboss-el/1.0_02.CR4/jboss-el-1.0_02.CR4.jar M2_REPO/org/jboss/seam/jboss-seam/2.2.0.GA/jboss-seam-2.2.0.GA.jar M2_REPO/org/jboss/seam/jboss-seam-jul/2.2.0.GA/jboss-seam-jul-2.2.0.GA.jar M2_REPO/org/jboss/seam/jboss-seam-mail/2.2.0.GA/jboss-seam-mail-2.2.0.GA.jar M2_REPO/org/jboss/seam/jboss-seam-ui/2.2.0.GA/jboss-seam-ui-2.2.0.GA.jar M2_REPO/org/hibernate/java-persistence/jpa-api/2.0-cr-1/jpa-api-2.0-cr-1.jar M2_REPO/javax/faces/jsf-api/1.2_13/jsf-api-1.2_13.jar M2_REPO/com/sun/facelets/jsf-facelets/1.1.14/jsf-facelets-1.1.14.jar M2_REPO/javax/faces/jsf-impl/1.2_13/jsf-impl-1.2_13.jar M2_REPO/jstl/jstl/1.2/jstl-1.2.jar M2_REPO/javax/transaction/jta/1.1/jta-1.1.jar M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar M2_REPO/javax/mail/mail/1.4.1/mail-1.4.1.jar M2_REPO/postgresql/postgresql/8.4-701.jdbc3/postgresql-8.4-701.jdbc3.jar M2_REPO/org/primefaces/primefaces-stable/1.0.0/primefaces-stable-1.0.0.jar M2_REPO/quartz/quartz/1.6.0/quartz-1.6.0.jar M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar M2_REPO/org/slf4j/slf4j-api/1.5.8/slf4j-api-1.5.8.jar M2_REPO/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jar M2_REPO/org/testng/testng/5.9/testng-5.9.jar M2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jar Java Developer Conference 2010 M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar
  48. 48. Repositories • Repositories are for managing build artifacts and dependencies • local or remote repositories • Can store jar, war, ear, ejb, rar .... • Maven looks to at least 2 repository if none specified - local one - http://repo1.maven.org/maven2 /uber-pom/ • Release & Snapshot repositories Java Developer Conference 2010
  49. 49. Repositories <repository> <id>jboss-repo</id> <name>The Release JBoss maven repo</name> <url>http://repository.jboss.org/maven2</url> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>jboss-snapshot-repo</id> <name>The Snapshot JBoss maven repo</name> <url>http://snapshots.jboss.org/maven2</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> Java Developer Conference 2010
  50. 50. Create Your own Repo • Go Corporate ! • Deploy and share your projects artifacts across your team • Cache dependencies Decrease the internet dependency • Proxy Repo configurations • OSS Alternatives: Nexus Archiva Artifactory Java Developer Conference 2010
  51. 51. Sonatype Nexus Nexus Repository Manager • Just a Web App, nice UI • Upload artifacts via HTTP, RESTful style • Indexing and searching for repository artifacts • LDAP Integration with v1.5 Nexus Professional ($$$) - Staging repository - Eclipse plugin repository and more... Java Developer Conference 2010
  52. 52. Searching for Artifacts • http://repository.apache.org • http://www.jarvana.com • http://www.artifact-repository.org • http://mvnrepository.com • http://www.mvnbrowser.com • http://mavensearch.net Java Developer Conference 2010
  53. 53. PLUGINS Java Developer Conference 2010
  54. 54. Plugins • Plugin-oriented Architecture plugin for even compiling the code.. • A maven artifact w/ descriptor (plugin.xml) and one or more MOJOs • Plexus as its IoC Why not Spring? • Where to look for plugins: org.apache.maven.plugins org.codehaus.mojo Java Developer Conference 2010
  55. 55. Plugins available @ maven Packaging Integration jar war ear ejb Core rar pom shade Eclipse clean IDEA compiler deploy failsafe install Maven Tools Ant resources Reporting Repo Antlr site Antrun Changelog surefire Archetype Changes verifier Assembly Checkstyle Clover Others Cargo Help Javadocs jaxme Release PMD jetty Surefire-reports tomcat Java Developer Conference 2010
  56. 56. ARCHETYPES Java Developer Conference 2010
  57. 57. Archetypes • Templates for maven projects • Descriptor XML files + velocity templates • To create a maven project: mvn archetype:generate -DgroupId=org.egjug.jdc2010 -DartifactId=archetype-quickstart -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.0 Java Developer Conference 2010
  58. 58. Archetype Catalogs • Descriptor file to share Archetypes globally. <?xml version="1.0" encoding="UTF-8"?> <archetype-catalog> <archetypes> .... <archetype> <groupId>org.jboss.weld.archetypes</groupId> <artifactId>weld-jsf-servlet-minimal</artifactId> <version>1.0.0-BETA1</version> <description>....</description> </archetype>" ..... </archetypes> </archetype-catalog> • $!mvn archetype:generate -DarchetypeCatalog=http:// anonsvn.jboss.org/repos/weld/archetypes/tags/1.0.0- BETA1 Java Developer Conference 2010
  59. 59. Archetypes from Existing Project • Use an existing project as a seed for archetype $ mvn archetype:create-from-project • generated archetype under : target / generated-sources / archetype Java Developer Conference 2010
  60. 60. IDE Support Java Developer Conference 2010
  61. 61. Maven with IDEs • Eclipse 3.5 Galileo Eclipse IAM (formerly Q4E) m2eclipse maven-eclipse-plugin @ central-repo • NetBeans 6.8 out of the box - embedded maven • Intellij IDEA 9 out of the box - embedded maven maven-idea-plugin @ central-repo Java Developer Conference 2010
  62. 62. m2eclipse • Eclipse plug-in from Sonatype • Checkout maven project from Source Control • Create new Project from Archetype • Nice POM Editor • Embedded Maven Console • You might need subclipse & AJDT plugins. • A quick Demo... Java Developer Conference 2010
  63. 63. INCREASE YOUR MOJOTIVITY Java Developer Conference 2010
  64. 64. Maven Help Plugin mvn help:describe -Dplugin=<anygoal> • Lists & describes the goals of the plugin mvn help:system • Lists system properties and env. variables Java Developer Conference 2010
  65. 65. Use Profiles • Create profiles for : development, staging and production <profile> <id>production</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <debug>false</debug> <optimize>true</optimize> </configuration> <profiles> </plugin> <profile> </plugins> <activation> </build> </profile> <jdk>[1.3,1.6)</jdk> </activation> ... • invoke like </profile> $ mvn <phase> -Pproduction Java Developer Conference 2010
  66. 66. Property References env.* environment variables exposed by OS or Shell ${env.JAVA_HOME} project.* POM elements ${project.groupId} ${project.parent.groupId} settings.* Maven settings.xml properties ${settings.localRepository} ${foo} <properties> <foo>bar</foo> </properties> Java Developer Conference 2010
  67. 67. Debugging Maven • Output full error stacktrace mvn <anygoal> -e • Output for debugging mvn <anygoal> -X Always use when submitting questions or bug reports. Java Developer Conference 2010
  68. 68. GOOD PRACTICES • If you are starting from scratch, start with MAVEN..! • A Repository Manager is a MUST Have a Corporate Repo • Have a company specific POM, try to keep your POM simple portable avoid any hardcoding.. • Use profiles... • Use <dependencyManagement /> coerce Maven to use a particular version enforce consistency within projects Java Developer Conference 2010
  69. 69. GOOD PRACTICES • Make it so that you can, Release early, Release Often - Quick, easy and reproducible releases - CI tool integration • Each project should output its own artifact (SoC) • Use IDE integrations from stone age to iron age... •Do not ignore or skip your tests! -Dmaven.test.skip=true -Dmaven.test.failure.ignore=true Java Developer Conference 2010
  70. 70. Online Resources http://www.sonatype.com/book Maven: The Complete Reference Maven By Example m2eclipse Book Nexus Book http://www.maestrodev.com/better-build-maven Better Builds with Maven Java Developer Conference 2010
  71. 71. Questions Java Developer Conference 2010
  72. 72. Thank you Sponsored by:

×