安装前提:
1、 安装jdk(忽略)
2、 安装Maven
· 1)载Maven并解压,官网下载对应系统的按安装包,http://maven.apache.org/download.cgi
· 2)、解压下载Maven安装包,并把解压后的文件夹下的apache-maven文件夹移动到系统目录下,例如D:\Java下。
3)右键“计算机”,选择“属性”,之后点击“高级系统设置”,点击”“环境变量”,来设置环境变量,有以下系统变量需要配置:新建系统变量 MAVEN_HOME 变量值:D:\Java\apache-maven-3.1.1
编辑系统变量 Path 添加变量值: ;%MAVEN_HOME%\bin
4)、检验是否安装成功:在命令行提示符窗口, mvn --version 若出现以下情况说明配置成功
·
搭建私服
1、下载nexus,官方下载地址:http://www.sonatype.org/nexus/go
可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问题,可能是因为jdk版本问题,若无法启动请选择2.5或更早的版本
注:nexus 2.6版本之后不再支持jdk1.6
若下载war,则将其放置tomcat下的webapp目录中,改名为nexus,运行tomcat服务,即可访问http://localhost:8081/nexus 默认用户名:admin;密码admin123
若下载tag或者zip将其解压并拷贝到系统相关目录下,找到安装目录下的bin执行相关系统的启动命令,例如:Linux上执行nexus start,在window上执行nexus.bat启动服务,就可以访问http://localhost:8081/nexus 了。
配置使用:
在项目pom.xml中声明使用私服方式:
<repositories>
<repository>
<id>nexus-repository</id>
<name>TeamNexus Repository</name>
<url>http://10.110.13.14:8081/nexus/content/groups/inspur-jszx/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin</id>
<name>TeamNexus pluginRepository</name>
<url>http://10.110.13.14:8081/nexus/content/groups/inspur-jszx/</url>
</pluginRepository>
</pluginRepositories>
在Maven配置文件中配置setting.xml中配置使用私服方式:
<profiles>
……………
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>central</id>
<url>http://10.110.13.14:8081/nexus/content/groups/inspur-jszx/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://10.110.13.14:8081/nexus/content/groups/inspur-jszx/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
……………
<profiles>
部署构件至远程仓库
mvn deploy 用来将项目生成的构件分发到远程Maven仓库。本地Maven仓库的构件只能供当前用户使用,在分发到远程Maven仓库之后,所有能访问该仓库的用户都能使用你的构件。
在pom中配置如下:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Releases Repository</name>
<url>http://IP:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshots Repository</name>
<url>http://IP:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
在Settring.xml中加入验证配置信息:
<server>
<id>nexus-releases</id>
<username>neoyin</username>
<password>*****</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>neoyin</username>
<password>*****</password>
</server>
PS:
settings.xml中server元素下id的值必须与POM中repository或snapshotRepository下id的值完全一致