一、Ubuntu 下安装maven(并修改使用阿里云仓库地址)
———————————————————-
1.apache项目管理软件,解决项目的依赖关系
2.下载apache-maven
3.tar 开,移动到 /soft下,并创建符号链接
4.配置环境变量
M2_HOME=”/soft/maven”
PATH=”…:/soft/maven/bin”
5.修改配置文件 /…/maven/conf/settings.xml
<mirror>
<id>nexus-osc</id>
<mirrorOf>central</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>nexus-osc-thirdparty</id>
<mirrorOf>thirdparty</mirrorOf>
<name>Nexus osc thirdparty</name>
<url>http://maven.aliyun.com/nexus/content/repositories/thirdparty/</url>
</mirror>
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
二、在windows上安装maven
—————————————————–
a.下载Maven的安装包,下载链接:http://maven.apache.org/download.cgi
b.下载后的文件为apache-maven-3.2.5-bin.zip 压缩包,将其解压到一个固定的文件夹。
c.修改环境变量。打开系统属性面板(在桌面上右击”我的电脑” ->”属性”->”高级系统设置”),
然后点击”环境变量” ->”新建”->输入”M2_HOME”和Maven解压后的根目录路径
(我解压到C:tools下所以完整的路径就是C:toolsapache-maven-3.2.5)
然后点击确定,再然后找到名为Path的系统变量,
单击选中后点击”编辑”,将%M2_HOME%bin;添加到变量值的开头(注意最后的分号也添加的)。
d.验证是否安装成功。点击windows左下角的”开始”,在搜索框中输入cmd,然后回车就可以打开windows的命令提示符窗口,
然后输入 echo %M2_HOME% 命令查看设置的环境变量,输入mvn -v 查看maven的版本
e.生成Maven本地仓库。在Maven项目中,用户无需像以前一样自己下载依赖的jar包再放入项目中,
只需要定义项目的 pom.xml 文件,对项目使用Maven命令时,Maven会自动从网络上下载相应的包到本地仓库,
项目就可以直接使用本地仓库的包。
第一次安装Maven时在windows的命令提示符窗口输入 mvn help:system 命令然后回车,
等其执行完后就可以在 C:UsersAdmin.m2repository 看到 Maven 下载的一些文件。
f.用户自定义配置。Maven有一个全局配置文件为 Maven根目录/conf/settings.xml 文件
(比如我的就是 C:toolsapache-maven-3.2.5confsettings.xml),Maven默认是使用此配置文件,
所有用户共享此配置。但是推荐每一个用户配置自己的配置文件,防止无意思影响系统中其他用户,
只需要将全局的配置文件复制到用户目录下的 .m2 文件夹即可(我的当前用户是 Admin,
所以复制后为 C:UsersAdmin.m2settings.xml )。
(如果没有 .m2 文件夹 请先执行上一步,maven会在当前用户的目录下生成 .m2 文件夹)。
三、在宿主机(win10)上安装maven本地仓库服务器
——————————————————-
1.安装tomcat
2.将nexus.war 移动到 tomcat安装目录下的webapps下
3.启动tomcat /soft/tomcat/bin/startup.bat
4.进入web界面 http://localhost:8080/,查看tomcat是否安装成功
5.修改默认的仓库地址为d:/maven-repo/nexus
[D:Program Files (x86)apache-tomcat-7.0.6webappsnexusWEB-INFclassesnexus.properties]
nexus-work=d:/maven-repo/nexus
6.配置maven,使用本地仓库服务器
a.修改配置文件 /soft/maven/conf/settings.xml
<mirror>
<id>nexus-osc</id>
<mirrorOf>central</mirrorOf>
<name>Nexus osc</name>
<url>http://192.168.0.104:8080/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>nexus-osc-thirdparty</id>
<mirrorOf>thirdparty</mirrorOf>
<name>Nexus osc thirdparty</name>
<url>http://192.168.0.104:8080/nexus/content/repositories/thirdparty/</url>
</mirror>
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.0.104:8080/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.0.104:8080/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
7.启动本地仓库服务器–tomcat
8.登录webui http://192.168.0.104:8080/nexus
四、在eclipse 上配置maven
———————————————————-
1.如果是最新版的eclipse,已经集成了maven
2.如果不是,需要在eclipse中下载maven插件
a.eclipse–> help–> install new soft–> 搜索maven进行下载安装
3.eclipse–> Preferences –> Maven –> installations –>add–> 添加你的maven地址
4.user settings –> browse –> 选择meven/conf/settings.xml
global settings –> browse –> 选择meven/conf/settings.xml
5.apply and close
文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览92005 人正在系统学习中
来源:葛红富
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!