Apache maven 2 overview

1,416 views

Published on

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

No Downloads
Views
Total views
1,416
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • TODO: replace screen-shot to generalize examples groupId, artifactId
  • Apache maven 2 overview

    1. 1. Apache Maven 2. Part 1: Overview Getting started with Apache Maven 2 Nikolay Khasanov, Anatoly Kondratyev October 201223 January 2013 Exigen Services confidential Exigen Services confidential
    2. 2. The Goal• Understand Maven principles• Build project with Maven• Compare to Apache Ant Exigen Services confidential 2
    3. 3. What is Maven? GETTING STARTEDExigen Services confidential 3
    4. 4. Glossary• Artifact • .jar, .ear, .war, .pom, etc. • GroupId, ArtifactId, Version• Maven repository • Holds artifacts• Dependency• POM file (Project Object Model) Exigen Services confidential 4
    5. 5. What is Maven?• Build automation tool• Open Source: Apache License 2.0• Knowledge accumulator• Declarative logic instead of imperative Exigen Services confidential 5
    6. 6. Maven’s Objectives• Making the build process easy• Providing a uniform build system• Providing quality project information• Providing guidelines for best practices development Exigen Services confidential 6
    7. 7. Change your mind CORE MAVEN 2Exigen Services confidential 7
    8. 8. Maven project pom.xml Project Dependency Object Manager Model Project lifecycle Repositories plug-in plug-in plug-in source generated resources binary code code files Exigen Services confidential 8
    9. 9. Project Object Model (pom.xml) project• Identification groupId home Spring 2.5.6• Hierarchy artifactId version parentsources type Junit• Structure my-app 4.5 classes Repository• Dependencies my-app another-app Servlet• Build settings API etc. 2.5 Exigen Services confidential 9
    10. 10. Super POM• Package: jar• Default project structure• Default artifacts Repository• Default plugins Exigen Services confidential 10
    11. 11. Default folders structure Exigen Services confidential 11
    12. 12. Maven does your work• Store only source code• Maven knows how to build• Dependencies are stored in shared repository Exigen Services confidential 12
    13. 13. Transitive dependencies my-app dependency.1 dependency.2 dependency.3dependency.1.1 dependency.1.2 Exigen Services confidential 13
    14. 14. Dependency scope Result Compile Runtime Test LookupScope classpath classpath classpath repositorycompile + + + +provided + - + +runtime - + + +test - - + +system + - + -import Maven 2.0.9 or later, replaces POM with <dependencyManagement> Exigen Services confidential 14
    15. 15. Maven Repository Local repository External repositories user local internal external Central (default) Maven User workstation Local network Internet Exigen Services confidential 16
    16. 16. Simple Maven project example MAVEN IN ACTIONExigen Services confidential 17
    17. 17. Installation1. Requirements: • JRE/JDK 1.4 or higher2. Download3. Unzip4. Setup environment variables: • M2_HOME • M2 • PATH5. Enjoy  Exigen Services confidential 18
    18. 18. Configuration• Global • <M2_HOME>/conf/settings.xml• User local • <USER_HOME>/.m2/settings.xml Exigen Services confidential 19
    19. 19. mvn• mvn [goal(s)] [phase(s)] [options] • goal = plugin:goal • phase = phase-name• Examples: • mvn compiler:compile • mvn install –X –DsomeProperty=10 Exigen Services confidential 21
    20. 20. Build lifecycle1. validate check pom.xml2. compile compile the source3. test run unit tests4. package create jar/war/...5. integration-test run integration tests6. verify verify the package7. install publish package to local repo8. deploy publish package to remote repo Exigen Services confidential 22
    21. 21. Start-up new projectmvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.exigenservices.training -DartifactId=myjsfResult: • Default folder structure • pom.xml • First java class • First unit-test class Exigen Services confidential 23
    22. 22. pom.xml: Minimal POM<project> <modelVersion>4.0.0</modelVersion> <groupId>com.exigenservices.app</groupId> <artifactId>myjsf</artifactId> <version>SNAPSHOT</version></project> Exigen Services confidential 24
    23. 23. pom.xml: Dependencies<project> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.6</version> <scope>test</scope> </dependency> </dependencies></project> Exigen Services confidential 25
    24. 24. pom.xml: Plug-ins configuration<project> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build></project> Exigen Services confidential 26
    25. 25. Build project• mvn install 1. validate 2. compile 3. test 4. package 5. install Exigen Services confidential 27
    26. 26. Install and Deploy deploy local developer 1 internal local developer 2install … external local developer N Local network Internet Exigen Services confidential 28
    27. 27. When deploy is needed?• Release• Update snapshot • Available for other projects Exigen Services confidential 29
    28. 28. Add repository<repositories> <repository> <id>Jboss.repository</id> <url> http://repository.jboss.org/maven2 </url> </repository></repositories> Exigen Services confidential 30
    29. 29. Develop with pleasure! IDE INTEGRATIONExigen Services confidential 31
    30. 30. IDE list• InteliJ IDEA from 7.0• Eclipse (plug-in: “m2eclipse”)• NetBeans 6.5 Exigen Services confidential 32
    31. 31. IDE features• POM editor• Dependency synchronization• Lifecycle build runners Exigen Services confidential 33
    32. 32. Let’s summarize CONCLUSIONExigen Services confidential 34
    33. 33. Advantages (vs. Ant)• Know Maven – can build project• Dependency management• Less CM activities• Force to standardization• Readable pom.xml• High reusability Exigen Services confidential 35
    34. 34. Disadvantages (vs. Ant)• Understanding• Artifacts search• Plug-ins documentation• “Exotic things” - maven-ant-plugin• Difficult to move from Ant Exigen Services confidential 36
    35. 35. Maven repositories• Central http://repo1.maven.org/maven2/• Central repository Explorer http://mvnrepository.com• Collection of plugins for Maven 2 http://mojo.codehaus.org• JBoss http://repository.jboss.com/maven2/• Sun http://download.java.net/maven/2/• Atlassian http://repository.atlassian.com/maven2/ Exigen Services confidential 37
    36. 36. References• Maven site http://maven.apache.org• Quick guide http://maven.apache.org/guides/MavenQuickReferenceCard.pdf• Maven FAQ http://docs.codehaus.org/display/MAVENUSER/FAQs-1• Better Builds with Maven. John Casey and others http://www.exist.com/better-build-maven• Maven overview in Russian http://www.ibm.com/developerworks/ru/edu/j-mavenv2/index.html• m2eclipse plug-in http://m2eclipse.codehaus.org Exigen Services confidential 38
    37. 37. Now it’s your turn… QUESTIONSExigen Services confidential 39

    ×