Maven2交流

646 views

Published on

内部交流培训文档,主要介绍Maven的基础知识,安装,使用

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

No Downloads
Views
Total views
646
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Maven2交流

  1. 1. Email lcycenter@gmail.com
  2. 2. }  Maven2}  Maven2}  Maven2
  3. 3. }  Maven2 ◦  ◦  ◦  ◦  ◦ }  Maven2 ◦  Maven2 ◦  Maven2 Ant ◦  Maven2 Ant
  4. 4. }  ◦  ◦  ◦  Eclipse/Netbean/IntelliJ IDEA/… ◦  maven}  ◦  –  -> -> -> -> ◦  ANT ◦  ANT ◦  –  Tomcat/Jetty –  – } 
  5. 5. }  & ◦  JAR ◦ }  ◦  IDE ◦ 
  6. 6. } } } } }  (Goals)}  (archetype)
  7. 7. groupId:artifactId:packaging:version
  8. 8. pom.xmlProject1 pom.xmlProject2 pom.xmlProject3
  9. 9. }  public / private / locale / …}  Maven ◦  (POM.xml + JAR/WAR) ◦  Maven ◦  /<groupId>/<artifactId>/<version>/<artifactId>- <version>.<packaging> –  org.apache.commons:commons-email:1.1 –  /org/apache/commons/commons-email/1.1/}  mvn install}  Maven ◦  http://repository.sonatype.org/index.html ◦  http://www.mvnbrowser.com/ ◦  http://www.mvnrepository.com/
  10. 10. <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> Scope</dependencies> • compile • provided}  • test}  JAR • runtime • system
  11. 11. validate validate the project is correct and all necessary information is available.generate-sources generate any source code for inclusion in compilationprocess-sources process the source code, for example to filter any valuesgenerate-resources generate resources for inclusion in the package.process-resources copy and process the resources into the destination directory, ready for packaging.compile compile the source code of the project.process-classes post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.generate-test-sources generate any test source code for inclusion in compilationprocess-test-sources process the test source code, for example to filter any values.generate-test-resources create resources for testing.
  12. 12. process-test- copy and process the resources into the test destination directory.resourcestest-compile compile the test source code into the test destination directorytest run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployedpackage take the compiled code and package it in its distributable format, such as a JAR.pre-integration-test perform actions required before integration tests are executed. This may involve things such as setting up the required environment.integration-test process and deploy the package if necessary into an environment where integration tests can be run.post-integration-test perform actions required after integration tests have been executed. This may including cleaning up the environmentverify run any checks to verify the package is valid and meets quality criteria.install install the package into the local repository, for use as a dependency in other projects locally.deploy done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
  13. 13. } }  Maven = +} }  $mvn jar:jar $mvn archetype:create …
  14. 14. }  mvn compile}  mvn clean}  mvn test}  mvn package}  mvn install}  Mvn jetty:run}  mvn javadoc:javadoc}  mvn site}  …
  15. 15. }  Maven2}  Maven2}  Maven2
  16. 16. }  Maven apache-maven-2.1.0-bin.zip}  2. %DEV_HOME%tools}  3. M2_HOME %DEV_HOME% toolsapache-maven-2.1.0}  4. M2: %M2_HOME%bin}  5. %M2% Path}  6. CMD c:mvn --version
  17. 17. }  Maven2}  Maven2}  Maven2
  18. 18. }  Builds}  Documentation}  Reporting}  Dependencies}  SCMs}  Releases
  19. 19. }  Maven2 ◦  EAR ◦  WAR ◦  JAR ◦  ZIP ◦  EJB
  20. 20. } }  mvn archetype:create - DgroupId=com.mycompany.ap - DartifactId=my-app ◦  –  -DgroupId= –  -DartifactId=
  21. 21. src/main/java Application/Library sourcessrc/main/resources Application/Library resourcessrc/main/webapps Web application sourcessrc/test/java Test sourcessrc/test/resources Test resourcessrc/site SiteLICENSE.txt Projects licenseREADME.txt Projects readme
  22. 22. } }  Maven2} } 
  23. 23. }  ebiz-app}  Java Package com.xxxx.ebiz}  ◦  app-util(jar): ◦  app-dao(jar): model / dao / ibatis ◦  app-web-common(jar) ◦  app-web-portal(war): ◦  app-web-console(war):
  24. 24. }  Plugin m2eclipse}  ◦  ◦  Coding ◦  mvn test ◦  mvn jetty:run ◦  Code Checkin ◦  mvn package ◦  mvn install
  25. 25. }  mvn compile}  mvn test}  mvn package}  mvn install}  mvn jetty:run

×