maven 服务搭建和使用

来源:互联网 发布:手机听歌软件 编辑:程序博客网 时间:2024/05/22 09:48

1.maven简介

Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。
Maven这个单词来自于意第绪语,意为知识的积累,最早在Jakata Turbine项目中它开始被用来试图简化构建过程。当时有很多项目,它们的Ant build文件仅有细微的差别,而JAR文件都由CVS来维护。于是Maven创始者开始了Maven这个项目,该项目的清晰定义包括,一种很方便的发布项目信息的方式,以及一种在多个项目中共享JAR的方式。

现在业界基本都会使用maven管理项目,可编译打包,单元测试等等;会用Nexus来做私服。

为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建。


2、Nexus下载

下载地址:http://www.sonatype.org/nexus/go 

 

3.安装配置 Nexus

 > 上传包 nexus-2.9.1-02-bundle.zip 到服务器上。

 > 解压 : unzip nexus-2.9.1-02-bundle.zip

 > 启动 :如下操作 

 

注:报错是指没有指定用户,需修改 nexus 脚本 > vi nexus 后找到 RUN_AS_USER 属性,做如下修改:

> 再启动


即可访问 http://localhost:8081/nexus/            

注:

localhost 指安装机器 IP 

默认登录用户 admin/admin123


配置

> 进入nexus系统,点击左侧 Repositories 


> 选中三项中的Configuration中的Download Remote indexs修改为true


> 选择Repair Index 让Nexus远程下载索引文件。


> 将3rd party 的Configuration中的Deploment Policy修改为Allow Redeploy:



如上 私服基本配置完成。

4 需要下载  apache-maven-3.0.4-bin.zip  解压,配置环境变量。 M2_HOME

需要path 增加 %M2_HOME%/bin

确认maven 是否可用: mvn -version

 

配置maven 的settings.xml文件:

settings.xml

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <settings xmlns="<a target=_blank href="http://maven.apache.org/SETTINGS/1.0.0">http://maven.apache.org/SETTINGS/1.0.0</a>xmlns:xsi="<a target=_blank href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"  
  3.     xsi:schemaLocation="<a target=_blank href="http://maven.apache.org/SETTINGS/1.0.0">http://maven.apache.org/SETTINGS/1.0.0</a> <a target=_blank href="http://maven.apache.org/xsd/settings-1.0.0.xsd">http://maven.apache.org/xsd/settings-1.0.0.xsd</a>">  
  4.   <localRepository>f:/.m2/repository</localRepository>  
  5.     <profiles>  
  6.         <profile>  
  7.             <id>DefaultProfile</id>  
  8.             <activation>  
  9.                 <activeByDefault>true</activeByDefault>  
  10.             </activation>  
  11.             <repositories>  
  12.              <repository>  
  13.               <id>nexus</id>  
  14.                     <name>nexus</name>  
  15.                     <url><span style="color:#ff6666;">http://10.10.113.195:8081/nexus/content/groups/public</span></url>  
  16.                     <layout>default</layout>  
  17.                     <releases>  
  18.                        <enabled>true</enabled>  
  19.                     </releases>  
  20.                     <snapshots>  
  21.        <enabled>true</enabled>  
  22.                     </snapshots>  
  23.              </repository>  
  24.                 <repository>  
  25.                     <id>maven2-repository.dev.java.net</id>  
  26.                     <name>Java.net Repository for Maven</name>  
  27.                     <url>http://download.java.net/maven/2/</url>  
  28.                     <layout>default</layout>  
  29.                 </repository>  
  30.             </repositories>   
  31.         </profile>  
  32.     </profiles>  
  33.     <servers>  
  34.         <server>  
  35.             <id>nexus-releases</id>  
  36.             <username>admin</username>  
  37.             <password>admin123</password>  
  38.         </server>  
  39.         <server>  
  40.             <id>nexus-snapshots</id>  
  41.             <username>admin</username>  
  42.             <password>admin123</password>  
  43.         </server>  
  44.         <server>  
  45.             <id>nexus-3dparty</id>  
  46.             <username>admin</username>  
  47.             <password>admin123</password>  
  48.         </server>  
  49.     </servers>  
  50.       
  51.     <activeProfiles>  
  52.      <activeProfile>nexus</activeProfile>  
  53.     </activeProfiles>  
  54. </settings>  

红色字体为maven仓库路径。

> JAVA IDE 中需要引用maven 配置

注:IDE需要maven插件,资源中已上传。

 

一个maven 工程,非常简单的springMVC 工程,资源中存放,请参考。

 

0 0