Chinaunix首页 | 论坛 | 博客
  • 博客访问: 636529
  • 博文数量: 17
  • 博客积分: 248
  • 博客等级: 二等列兵
  • 技术积分: 237
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-26 12:13
个人简介

别让往昔的悲伤和对未来的恐惧,毁了你当下的幸福。

文章分类

全部博文(17)

文章存档

2013年(6)

2012年(2)

2011年(9)

我的朋友

分类: 项目管理

2013-03-01 17:09:57


点击(此处)折叠或打开

  1. Apache Maven’s objectives are listed as:
  2. 1. Making the build process easy
  3. 2. Providing a uniform build system
  4. 3. Providing quality project information
  5. 4. Providing guidelines for best practices in development
  6. 5. Allowing transparent migration to new features
  7. 一. windows 安装maven
  8. 1.安装JDK 地址:you can download it at
  9. 2.下载Mave:,并解压,注意path不要包含空格。
  10. 3.设置环境变量:M2_HOME:解压目录
  11. 4.设置环境变量:MAVEN_OPTS:-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m #项目的module多时防止内存溢出.
  12. 5.将mave的命令加入path:;%M2_HOME%bin
  13. 二. linux 安装maven
  14. 重复windows下的1,2步骤,
  15. 3.编辑用户目录下的.bashrc文件加入:
  16. export M2_HOME=/home/srirangan/apache-maven-3.0.2
  17. export MAVEN_OPTS=-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m #项目的module多时防止内存溢出.
  18. export PATH=${PATH}:${M2_HOME}/bin
  19. 三. 确认mave是否安装成功。
  20. 在commoand line/shell下输入mvn -version如果出现以下内容说明成功(linux下输出有所不同),如果没有检查环境变量的设置:
  21. Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
  22. Maven home: D:apache-maven-3.0.3-binapache-maven-3.0.3
  23. Java version: 1.6.0_26, vendor: Sun Microsystems Inc.
  24. Java home: D:Javajdk1.6.0_26jre
  25. Default locale: zh_CN, platform encoding: GBK
  26. OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
  27. 四. Creating a new project
  28. windowns下为例,在命令行输入:mvn archetype:generate
  29. 然后回输出一堆信息,提示让你输入个number来选择生成方式,默认251就是建立一个简单的java project,接着会提示让你输入groupId,这简单提一下,mave里的project是靠坐标("project co-ordinates" such as groupId,artifactId, version, and package)来标识其唯一性的,我的输入如下:
  30. Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 251:
  31. Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
  32. 1: 1.0-alpha-1
  33. 2: 1.0-alpha-2
  34. 3: 1.0-alpha-3
  35. 4: 1.0-alpha-4
  36. 5: 1.0
  37. 6: 1.1
  38. Choose a number: 6:
  39. Define value for property 'groupId': : org.guarx.mvn
  40. Define value for property 'artifactId': : guarx-mvn
  41. Define value for property 'version': 1.0-SNAPSHOT: :
  42. Define value for property 'package': org.guarx.mvn: :
  43. 然后 Y
  44. 看到成功的提示,说明项目创建成功,可以看到目录结构guarx-mvn下就一个src和pom.xml,以后的配置都在pom.xml里。
  45. 五.Compiling and testing a project
  46. 在command line下执行
  47. mvn compile(编译),
  48. 编译完会在src目录下生成一个target文件夹,里面放了compile完后的一些文件包括class
  49. mvn test(测试,Maven to run the tests present in the .../src/test folder),测试的主要结果会输出如下:
  50. -------------------------------------------------------
  51. T E S T S
  52. -------------------------------------------------------
  53. Running org.guarx.mvn.AppTest
  54. Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.098 sec
  55. Results :
  56. Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
  57. 六. POM
  58. 每个mave的project都包含个pom.xml(Project Object Model),pom文件的结构如下:
  59. 4.0.0
  60. ...
  61. ...
  62. ...
  63. ...
  64. ...
  65. ...
  66. ...
  67. ...
  68. ...
  69. ...
  70. ...
  71. ...
  72. ...
  73. ...
  74. ...
  75. ...
  76. ...
  77. ...
  78. ...
  79. ...
  80. ...
  81. ...
  82. ...
  83. ...
  84. ...
  85. ...
  86. ...
  87. ...
  88. 项目坐标(Project coordinates),pom 文件用groupId,artifactId,version来确定project coordinates.a
  89. 对于pom文件结构包含4个主要部分,下面是说明:
  90. The basics: This section contains project co-ordinates, dependency management, andinheritance details. Additionally, it also contains modules and project level properties.
  91. Build settings: This section contains the build details.
  92. Project metadata: This section contains project-specific details such as name,organization, developers, URL, inception year, and so on.
  93. Environment: This section contains all information regarding the environmentincluding details of the version control being, issue management, continuousintegration, mailing lists, repositories, and so on.
  94. 七. Build Lifecycle
  95. 在每个maven的项目构建生命周期在构建,测试,发布过程够被明确定义。
  96. 在每个过程中里包含有: default, clean, and site,三个生命周期。
  97. Default Lifecycle;
  98. Validate: validates that all project information is available and is correct
  99. Compile: compiles the source code
  100. Test: runs unit tests within a suitable framework
  101. Package: packages the compiled code in its distribution format
  102. Integration-test: processes the package in the integration-test environment
  103. Verify: runs checks to verify that the package is valid
  104. Install: installs the package in the local repository
  105. Deploy: installs the final package in a remote repository
  106. Clean lifecycle:
  107. Pre-clean: executes processes required before project cleaning
  108. Clean: removes all files generated by previous builds
  109. Post-clean: executes processes required to finalize project cleaning
  110. Site lifecycle:
  111. Pre-site: executes processes required before generation of the site
  112. Site: generates the project’s site documentation
  113. Post-site: executes processes required to finalize the site generation and prepares the site for deployment
  114. Site-deploy: deploys the site documentation to the specified web server
  115. 八 Build profiles
  116. 构建是的配置,
  117. 使用配置:mvn install -P profile-1,profile-2
  118. 不使用配置:mvn install -P !profile-1,!profile-2
  119. 在系统用户目录下有个.m2文件夹,这有个settings.xml是对mvn构建动作的全局配置,这就定义了一个默认的profile,也可以在项目的pom.xml里定义profile构建的时候并制定profile,这样默认的profile会被覆盖掉.
  120. 第一章的内容到此结束.

阅读(1197) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~