Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Apache maven 2 overview

695 Aufrufe

Veröffentlicht am

Webinar presentation http://www.returnonintelligence.ru/webinars/apachemaven2/

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Apache maven 2 overview

  1. 1. Exigen Services confidential Exigen Services confidential Apache Maven 2. Part 1: Overview Getting started with Apache Maven 2 Nikolay Khasanov, Anatoly Kondratyev October 2012 20 July 2015
  2. 2. Exigen Services confidential The Goal • Understand Maven principles • Build project with Maven • Compare to Apache Ant 2
  3. 3. Exigen Services confidential GETTING STARTED What is Maven? 3
  4. 4. Exigen Services confidential Glossary • Artifact • .jar, .ear, .war, .pom, etc. • GroupId, ArtifactId, Version • Maven repository • Holds artifacts • Dependency • POM file (Project Object Model) 4
  5. 5. Exigen Services confidential What is Maven? • Build automation tool • Open Source: Apache License 2.0 • Knowledge accumulator • Declarative logic instead of imperative 5
  6. 6. Exigen Services confidential Maven’s Objectives • Making the build process easy • Providing a uniform build system • Providing quality project information • Providing guidelines for best practices development 6
  7. 7. Exigen Services confidential CORE MAVEN 2 Change your mind 7
  8. 8. Exigen Services confidential Maven project pom.xml source code generated code resources binary files RepositoriesProject lifecycle plug-in plug-in plug-in Project Object Model Dependency Manager 8
  9. 9. Exigen Services confidential groupId artifactId version type Repository Project Object Model (pom.xml) • Identification • Hierarchy • Structure • Dependencies • Build settings my-app parent another-app Spring 2.5.6 Junit 4.5 Servlet API 2.5 my-app 9 project home sources classes etc.
  10. 10. Exigen Services confidential Super POM • Package: jar • Default project structure • Default artifacts Repository • Default plugins 10
  11. 11. Exigen Services confidential Default folders structure 11
  12. 12. Exigen Services confidential Maven does your work • Store only source code • Maven knows how to build • Dependencies are stored in shared repository 12
  13. 13. Exigen Services confidential Transitive dependencies my-app dependency.1 dependency.2 dependency.3 dependency.1.1 dependency.1.2 13
  14. 14. Exigen Services confidential Dependency scope Result Scope Compile classpath Runtime classpath Test classpath Lookup repository compile + + + + provided + - + + runtime - + + + test - - + + system + - + - import Maven 2.0.9 or later, replaces POM with <dependencyManagement> 14
  15. 15. Exigen Services confidential Maven Repository User workstation Local network Internet internal external Central (default) Local repository External repositories user local 16 Maven
  16. 16. Exigen Services confidential MAVEN IN ACTION Simple Maven project example 17
  17. 17. Exigen Services confidential Installation 1. Requirements: • JRE/JDK 1.4 or higher 2. Download 3. Unzip 4. Setup environment variables: • M2_HOME • M2 • PATH 5. Enjoy  18
  18. 18. Exigen Services confidential Configuration • Global • <M2_HOME>/conf/settings.xml • User local • <USER_HOME>/.m2/settings.xml 19
  19. 19. Exigen Services confidential mvn • mvn [goal(s)] [phase(s)] [options] • goal = plugin:goal • phase = phase-name • Examples: • mvn compiler:compile • mvn install –X –DsomeProperty=10 21
  20. 20. Exigen Services confidential Build lifecycle 1. validate 2. compile 3. test 4. package 5. integration-test 6. verify 7. install 8. deploy 22 check pom.xml compile the source run unit tests create jar/war/... run integration tests verify the package publish package to local repo publish package to remote repo
  21. 21. Exigen Services confidential Start-up new project mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.exigenservices.training -DartifactId=myjsf 23 Result: • Default folder structure • pom.xml • First java class • First unit-test class
  22. 22. Exigen Services confidential pom.xml: Minimal POM <project> <modelVersion>4.0.0</modelVersion> <groupId>com.exigenservices.app</groupId> <artifactId>myjsf</artifactId> <version>SNAPSHOT</version> </project> 24
  23. 23. Exigen Services confidential pom.xml: Dependencies <project> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.6</version> <scope>test</scope> </dependency> </dependencies> </project> 25
  24. 24. Exigen Services confidential 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> 26
  25. 25. Exigen Services confidential Build project 27 • mvn install 1. validate 2. compile 3. test 4. package 5. install
  26. 26. Exigen Services confidential Install and Deploy 28 developer 1local developer 2local developer Nlocal … install internal external Local network Internet deploy
  27. 27. Exigen Services confidential When deploy is needed? • Release • Update snapshot • Available for other projects 29
  28. 28. Exigen Services confidential Add repository <repositories> <repository> <id>Jboss.repository</id> <url> http://repository.jboss.org/maven2 </url> </repository> </repositories> 30
  29. 29. Exigen Services confidential IDE INTEGRATION Develop with pleasure! 31
  30. 30. Exigen Services confidential IDE list • InteliJ IDEA from 7.0 • Eclipse (plug-in: “m2eclipse”) • NetBeans 6.5 32
  31. 31. Exigen Services confidential IDE features • POM editor • Dependency synchronization • Lifecycle build runners 33
  32. 32. Exigen Services confidential CONCLUSION Let’s summarize 34
  33. 33. Exigen Services confidential Advantages (vs. Ant) • Know Maven – can build project • Dependency management • Less CM activities • Force to standardization • Readable pom.xml • High reusability 35
  34. 34. Exigen Services confidential Disadvantages (vs. Ant) • Understanding • Artifacts search • Plug-ins documentation • “Exotic things” - maven-ant-plugin • Difficult to move from Ant 36
  35. 35. Exigen Services confidential 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/ 37
  36. 36. Exigen Services confidential 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 38
  37. 37. Exigen Services confidential QUESTIONS Now it’s your turn… 39

×