虽然最近一直在用maven,但是由于学校网速尚可,所以对私服的需求不不高,所以一直都没有搭建过nexus。现在新买了一台笔记本,觉得刚好可以搭建个私服,给两台电脑的maven都可以使用到nexus。顺便学习下如何搭建nexus。
具体操作如下:
一、下载maven,地址如下:http://maven.apache.org/download.cgi
选择合适自己系统版本的即可
二、下载nexus仓库,地址如下:http://www.sonatype.org/nexus/
三、 搭建nexus仓库,现在的安装nexus并不需要tomcat了(因为它内置了一个Jetty),直接进入到nexus的解压路径中的,nexus-2.8.0-05-bundle\nexus-2.8.0-05\bin\jsw文件夹中,选择自己系统对应的版本,由于作则的是win 8.1 64位。所以选择windows-x86-64,然后点击 install-nexus.bat 即可。到此,nexus安装完毕。
四、配置nexus
1、 在浏览器中输入地址:http://127.0.0.1:8081/nexus/#welcome,打开。
2、在右上角处,点击 log in。输入账号admin,密码admin123.,登陆
3、在左边处选择“Repositories”,如图
4、分别双击这三个
,每个都选择
保存,然后三个分别右击,选择Repaire index。
5、配置maven
a.在maven安装目录下找到conf文件夹,修改setting.xml文件夹,添加上<localRepository>H:\maven_jar</localRepository>,标签里面的为以后maven所为你下载jar包的路径。
b.在最后一行</setting>前添加下面一段
<mirrors>
<mirror>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
<profile>
<id>nexus-snapshots</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus snapshots</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>
其中,不准备安装的nexus的那台电脑,要把上面的的ip地址修改为安装有nexus的电脑的地址。比如我的两台电脑中,一台是台式,一台是笔记本,其中台式安装nexus,而笔记本中并不安装,所以,我希望的是,笔记本maven以后从台式机中的nexus中下载jar包(上传的功能现在还并不需要)。所以,我把笔记本中的maven中的setting.xml中的修改成以下版本
<mirrors>
<mirror>
<id>nexus</id>
<url>http://10.0.22.234:8081/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://10.0.22.234:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
<profile>
<id>nexus-snapshots</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus snapshots</name>
<url>http://10.0.22.234:8081/nexus/content/groups/public-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>
到此,maven配置完成。
最后配置MyEclipse中的maven插件和自己的maven关联起来
windows--preference--MyEclipse--Maven4Myeclipse--installation--点击右边的"Add",选择自己maven的路径。如图
再选择UserSetting,设置setting.xml的路径。
检测下结果,查看nexus路径下的nexus-2.8.0-05-bundle\sonatype-work\nexus\storage\central\jstl\jstl。没有这个文件夹或者有这个文件夹但没有东西。
然后在MyEclipse新建个maven项目里面的pom文件中添加依赖
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
保存,等maven执行完成后,会发现刚才所说的文件夹里面会出现1.1.2文件夹。里面有jar文件。如果使用笔记本中的maven也是。