Advertisement
Advertisement

More Related Content

Advertisement

Apache maven 2 overview

  1. Apache Maven 2. Part 1: Overview Getting started with Apache Maven 2 Nikolay Khasanov, Anatoly Kondratyev October 2012 23 January 2013 Exigen Services confidential Exigen Services confidential
  2. The Goal • Understand Maven principles • Build project with Maven • Compare to Apache Ant Exigen Services confidential 2
  3. What is Maven? GETTING STARTED Exigen Services confidential 3
  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. What is Maven? • Build automation tool • Open Source: Apache License 2.0 • Knowledge accumulator • Declarative logic instead of imperative Exigen Services confidential 5
  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. Change your mind CORE MAVEN 2 Exigen Services confidential 7
  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. 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. Super POM • Package: jar • Default project structure • Default artifacts Repository • Default plugins Exigen Services confidential 10
  11. Default folders structure Exigen Services confidential 11
  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. Transitive dependencies my-app dependency.1 dependency.2 dependency.3 dependency.1.1 dependency.1.2 Exigen Services confidential 13
  14. Dependency scope Result Compile Runtime Test Lookup Scope classpath classpath classpath repository compile + + + + provided + - + + runtime - + + + test - - + + system + - + - import Maven 2.0.9 or later, replaces POM with <dependencyManagement> Exigen Services confidential 14
  15. Maven Repository Local repository External repositories user local internal external Central (default) Maven User workstation Local network Internet Exigen Services confidential 16
  16. Simple Maven project example MAVEN IN ACTION Exigen Services confidential 17
  17. Installation 1. Requirements: • JRE/JDK 1.4 or higher 2. Download 3. Unzip 4. Setup environment variables: • M2_HOME • M2 • PATH 5. Enjoy  Exigen Services confidential 18
  18. Configuration • Global • <M2_HOME>/conf/settings.xml • User local • <USER_HOME>/.m2/settings.xml Exigen Services confidential 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. Build lifecycle 1. validate check pom.xml 2. compile compile the source 3. test run unit tests 4. package create jar/war/... 5. integration-test run integration tests 6. verify verify the package 7. install publish package to local repo 8. deploy publish package to remote repo Exigen Services confidential 22
  21. Start-up new project mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.exigenservices.training -DartifactId=myjsf Result: • Default folder structure • pom.xml • First java class • First unit-test class Exigen Services confidential 23
  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. 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. 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. Build project • mvn install 1. validate 2. compile 3. test 4. package 5. install Exigen Services confidential 27
  26. Install and Deploy deploy local developer 1 internal local developer 2 install … external local developer N Local network Internet Exigen Services confidential 28
  27. When deploy is needed? • Release • Update snapshot • Available for other projects Exigen Services confidential 29
  28. Add repository <repositories> <repository> <id>Jboss.repository</id> <url> http://repository.jboss.org/maven2 </url> </repository> </repositories> Exigen Services confidential 30
  29. Develop with pleasure! IDE INTEGRATION Exigen Services confidential 31
  30. IDE list • InteliJ IDEA from 7.0 • Eclipse (plug-in: “m2eclipse”) • NetBeans 6.5 Exigen Services confidential 32
  31. IDE features • POM editor • Dependency synchronization • Lifecycle build runners Exigen Services confidential 33
  32. Let’s summarize CONCLUSION Exigen Services confidential 34
  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. Disadvantages (vs. Ant) • Understanding • Artifacts search • Plug-ins documentation • “Exotic things” - maven-ant-plugin • Difficult to move from Ant Exigen Services confidential 36
  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. 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. Now it’s your turn… QUESTIONS Exigen Services confidential 39

Editor's Notes

  1. TODO: replace screen-shot to generalize examples groupId, artifactId
Advertisement