使用Nexus来搭建本地的Maven服务器
.
在开发过程中,有时候会使用到公司内部的一些开发包,显然把这些包放在外部是不合适的。另外,由于项目一直在开发中,这些内部的依赖可能也在不断的更新。可以通过搭建公司内部的Maven服务器,将第三方和内部的依赖统一管理。 这里使用Nexus来搭建本地的Maven服务器,过程比较简单。
1,下载nexus. jdk1.6以及之前的版本,需要下载nexus2.5以下的版本。jdk1.7以上的需要下载2.5以上的版本。 nexus-2.2-01-bundle.tar.gz
解压nexus,有两个文件,一个是nexus,一个是jar包存放的服务器位置。
这里以nexus-2.2-01-bundle.tar.gz说明。 进入nexus-2.2-01\bin\jsw目录。选择对应的系统,查看自己电脑的jdk版本以及jdk是32位还是64位。 查看jdk是32位还是64位方法: 新建个测试类: String arch = System.getProperty("sun.arch.data.model"); System.out.println(arch);
输出是32就是32位,是64就是64位
运行install-nexus.bat 文件,win7使用管理员权限运行,第一次运行界面一闪而过,可以再次运行确定是否成功。 运行start-nexus.bat 文件,win7使用管理员权限运行,成功之后对话框消失,若出现错误,请确认nexus与Jdk版本是否匹配 浏览器输入http://localhost:8081/nexus,出现如下页面,则表示安装成功:
如果是端口占用,可以修改端口。在nexus-2.2-01\conf\nexus.properties中,修改默认端口: application-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus nexus-webapp-context-path=/nexus
点击右上角login in。 admin/admin123。进入操作界面。 点击左侧的Repositories,双击选择右侧的central.点击选中下方的configuration选项卡, 修改Dowload RemoteIndexs 属性为True,点击save.点击左侧的ScheduledTasks 可以在右侧,看到当前正在下载远程目录索引.则配置成功
2,在完成了上面的配置后,就可以将项目中默认的Repository切换为本地的私服了,只需要在pom.xml中增加repositories就可以了: <repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>public</id> <name>Public Repositories</name> <url>http://localhost:8081/nexus/content/groups/public</url> </repository> </repositories>
在项目pom.xml中,添加依赖包 <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>1.4</version> </dependency>
打开http://localhost:8081/nexus/content/groups/public,可以看到添加的commons-io包。在服务器(本地)存放的目录是sonatype-work\nexus\storage下。 |