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