maven 教程一 入门

Maven是一个采用纯Java编写的开 源项目管理工具。Maven采用了一种被称之为project object model (POM)概念来管理项目,所有的项目配置信息都被定义在一个叫做POM.xml的文件中,通过该文件,Maven可以管理项目的整个声明周期,包括编 译,构建,测试,发布,报告等等。目前Apache下绝大多数项目都已经采用Maven进行管理。而Maven本身还支持多种插件,可以方便更灵活的控制 项目。

下载好 Maven 后,需要简单安装下。将下载的  zip  或者  tar.gz  包解压到需要安装到的目录。 接下简单配置下环境变量:

1、新建环境变量  M2_HOME  ,输入值为 Maven 的安装目录。

2、新建环境变量  M2  ,输入值为:  %M2_HOME%\bin  。

3、将 M2 环境变量加入  Path  的最后,如:  ;%M2%  ;。

环境变量就这么简单配置下就可以了。打开命令行窗口输入  mvn -version  。可以看到如下输出:


 

看到以上输出,您的 Maven 环境就已经搭建好了。

2.修改 settings.xml

在 Maven 中使用 OSChina 的 Maven 服务还需要简单配置一下 Maven,在 Maven 的安装目录下的 conf 文件下有个  settings.xml  文件,接下来我们需要对这个文件做简单的修改,修改前您可以简单备份下该文件。 打开  settings.xml  文件,按下面内容修改。或者点击 settings.xml 下载


01 <mirrors>
02     <!-- mirror | Specifies a repository mirror site to use instead of a given
03         repository. The repository that | this mirror serves has an ID that matches
04         the mirrorOf element of this mirror. IDs are used | for inheritance and direct
05         lookup purposes, and must be unique across the set of mirrors. | -->
06     <mirror>
07         <id>nexus-osc</id>
08         <mirrorOf>*</mirrorOf>
09         <name>Nexus osc</name>
10         <url>http://maven.oschina.net/content/groups/public/</url>
11     </mirror>
12 </mirrors>

补充:   如果还需要osc的thirdparty仓库或多个仓库,需要如下修改:详情 
01 <mirrors>
02     <!-- mirror | Specifies a repository mirror site to use instead of a given
03         repository. The repository that | this mirror serves has an ID that matches
04         the mirrorOf element of this mirror. IDs are used | for inheritance and direct
05         lookup purposes, and must be unique across the set of mirrors. | -->
06     <mirror>
07         <id>nexus-osc</id>
08         <mirrorOf>central</mirrorOf>
09         <name>Nexus osc</name>
10         <url>http://maven.oschina.net/content/groups/public/</url>
11     </mirror>
12     <mirror>
13         <id>nexus-osc-thirdparty</id>
14         <mirrorOf>thirdparty</mirrorOf>
15         <name>Nexus osc thirdparty</name>
16         <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
17     </mirror>
18 </mirrors>

这里是配置 Maven 的 mirror 地址指向OSChina 的 Maven 镜像地址。 在执行 Maven 命令的时候, Maven 还需要安装一些插件包,这些插件包的下载地址也让其指向 OSChina 的 Maven 地址。修改如下内容。


01 <profile>
02     <id>jdk-1.4</id>
03  
04     <activation>
05         <jdk>1.4</jdk>
06     </activation>
07  
08     <repositories>
09         <repository>
10             <id>nexus</id>
11             <name>local private nexus</name>
12             <url>http://maven.oschina.net/content/groups/public/</url>
13             <releases>
14                 <enabled>true</enabled>
15             </releases>
16             <snapshots>
17                 <enabled>false</enabled>
18             </snapshots>
19         </repository>
20     </repositories>
21     <pluginRepositories>
22         <pluginRepository>
23             <id>nexus</id>
24             <name>local private nexus</name>
25             <url>http://maven.oschina.net/content/groups/public/</url>
26             <releases>
27                 <enabled>true</enabled>
28             </releases>
29             <snapshots>
30                 <enabled>false</enabled>
31             </snapshots>
32         </pluginRepository>
33     </pluginRepositories>
34 </profile>

如果您需要修改 Maven 的默认文件保存路径,需要在 settings.xml 文件中修改如下地方。


1 <localRepository>F:/Maven/repo/m2/</localRepository>

按照如上修改  settings.xml  之后,您就可以在自己的 Maven 中使用 OSChina 为您提供的 Maven 服务了。







 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值