1. 安装
在http://maven.apache.org/download.html 中下载最新版本
解压缩, 并且正确设置环境变量
具体操作如官方说明一样:
Windows 2000/XP
- Unzip apache-maven-2.0.8-bin.zip to the directory you wish to install Maven 2.0.8. These instructions assume you chose C:\Program Files\Apache Software Foundation\apache-maven-2.0.8
- Add the bin directory to your path, by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then editing the PATH variable in the user variables. eg. "C:\Program Files\Apache Software Foundation\apache-maven-2.0.8\bin";%PATH%
- In the same dialog, make sure that JAVA_HOME is set to the location of your JDK, eg. C:\Program Files\Java\jdk1.5.0_02
- Run mvn --version to verify that it is correctly installed.
Unix-based Operating Systems (Linux, Solaris and Mac OS X)
- Extract the distribution archive to the directory you wish to install Maven 2.0.8. These instructions assume you chose /usr/local/apache-maven-2.0.8 . The directory apache-maven-2.0.8 will be created from the archive.
- Add the bin directory to your path, eg. export PATH=/usr/local/apache-maven-2.0.8/bin:$PATH
- Make sure that JAVA_HOME is set to the location of your JDK, eg. export JAVA_HOME=/usr/java/jdk1.5.0_02
- Run mvn --version to verify that it is correctly installed.
2.生成Maven项目
生成标准布局的webapp项目,在控制台执行下面命令(groupId后面是包名,artifactId后面是项目名称):
mvn archetype:create -DgroupId=net.jeffrey
-DartifactId=my-webapp
-DarchetypeArtifactId=maven-archetype-webapp
生成标准布局的普通java项目,执行:
mvn archetype:create -DgroupId=net.jeffrey -DartifactId=my-app
完成后你会看到已经生成了一个名为my-webapp的文件夹,这就是刚刚生成好的项目目录
在my-webapp根目录下,你会看到名为pom.xml的文件,这个就是maven的项目描述文件
3.maven和eclipse整合
安装maven2插件 http://m2eclipse.codehaus.org/
网站中有详细的FLASH DEMO介绍安装和基本使用
4.架设artifactory私服管理
直接下载解压就可以使用
项目的pom.xml文件修改
<
repositories
>
<
repository
>
<
id
>
artifactory
</
id
>
<
name
>
your local artifactory
</
name
>
<
url
>
http://localhost:8081/artifactory/repo
</
url
>
</
repository
>
</
repositories
>

<
pluginRepositories
>
<
pluginRepository
>
<
id
>
artifactory
</
id
>
<
name
>
your local artifactory
</
name
>
<
url
>
http://localhost:8081/artifactory/plugins-releases
</
url
>
<
snapshots
>
<
enabled
>
false
</
enabled
>
</
snapshots
>
</
pluginRepository
>
</
pluginRepositories
>
具体的依赖写法,要参考 http://mvnrepository.com/
修改artifactory的下载地址为: <remoteRepository>
<key>repo1</key>
<handleReleases>true</handleReleases>
<handleSnapshots>false</handleSnapshots>
<excludesPattern>org/artifactory/**,org/jfrog/**</excludesPattern>
<!-- <url>http://repo1.maven.org/maven2</url>-->
<url>http://mirrors.redv.com/maven2</url>
</remoteRepository>
在/etc/artifactory.config.xml中!
5.与myeclipse的结合:
0. 为eclipse添加Maven2和MyEclipse插件
1. 将Maven项目转为Eclipse项目,具体操作为将dos命令窗口切换到Maven项目的目录下,输入命令: mvn eclipse:eclipse
2. 进入eclipse,将这个项目导入工作空间
3. 在该项目上点右键Maven->Enable
4. 在该项目上点右键Build Path->Configure Build Path->Java Build Path->Libraries->去掉Maven添加的变量路径
5. 在该项目上点右键MyEclipse->Add Web Capabilities->修改Web root地址(点【浏览】按钮指定为当前工作空间下的src/main/webapp文件夹)