本地私服可以: 上传jar包共享,还可以上传项目共享,可供局域网使用
本文使用maven版本: 3.3.9
度盘链接:https://pan.baidu.com/s/1DpyEoav9FcJs2v4H5Pu9-g
提取码:sl08
1.下载nexus官方压缩包
http://www.sonatype.org/nexus/go找到对应操作系统的版本下载,
本文下载得到的版本是: nexus-3.19.1-01-win64.zip
度盘链接:https://pan.baidu.com/s/1gSmEXm15KYoXd-YE5pwK4Q
提取码:amb0
2.解压
nexus-3.19.1-01-win64
3.运行
1. nexus.exe /run 命令可以启动nexus服务(参考官方文档)
2. 安装nexus本地服务来启动(推荐使用这种方式,参考官方文档),命令如下所示。
nexus.exe /install <optional-service-name> //安装nexus服务,一般不指定服务名称,默认为nexus
nexus.exe /start <optional-service-name> //启动nexus服务或cmd后执行net start nexus
nexus.exe /stop <optional-service-name> //停止nexus服务或cmd后执行net stop nexus
我们先临时使用第一种方法启动(可以观察启动有没有报错,后再注册为服务):
cmd进入真实目录: nexus-3.19.1-01-win64\nexus-3.19.1-01\bin
执行启动命令: nexus.exe /run
第一次启动会比较慢,默认登录地址是http://localhost:8081,你能打开这个地址说明就启动成功了
如果不成功就看报错
可以打开文件nexus-3.19.1-01-win64\nexus-3.19.1-01\etc\nexus-default.properties修改默认端口8081
4.登录
默认登录地址http://localhost:8081,输入用户名admin和密码admin123,点登录,会提示你密码错误,并告诉你初始密码的位置,
找到初始密码进行登录,系统会提示你修改密码,可以修改为admin123或其他密码5.配置本地maven指向本地私服
启动之后,系统默认会生成两个公共库: maven和nuget, 如果不想新建,可以使用默认的
如果使用默认的, 我们修改maven/conf/settings.xml指向私服地址
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
6.注册maven没有的jar包,入sqljdbc4,ojdbc14等
注册sqljdbc4:
由于微软没有提供sqljdbc4的maven坐标,所以需要自己下载jar包进行添加依赖
sqljdbc4的jar包微软的官方下载地址
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774
度盘链接:https://pan.baidu.com/s/11UTtmYL_96U5FU9-_6b35Q
提取码:hifz
注册到本地私服仓库
1.命令行(推荐)
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0
2.界面上Upload
这样就可以在pom.xlm引用了
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
卸载sqljdbc4
语法:
mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId, ..."
实际:
mvn dependency:purge-local-repository -DmanualInclude="com.microsoft.sqlserver:sqljdbc4"
7.新建自己的仓库,命名按maven仓库来
需要新建group(仓库组),hosted(宿主仓库),proxy(代理仓库)
proxy:即设置代理,在你的nexus中找不到的依赖就会去代理的地址中找
hosted:你可以上传你自己的项目到这里面
group:它可以包含前面两个,是一个聚合体。一般用来给客户一个访问nexus的统一地址
Create repository->maven2(hosted)->my-releases : 其中Hosted的Deployment policy选择Allow redeploy
Create repository->maven2(proxy)->my-central : 其中在Enter a URL写默认地址https://repo1.maven.org/maven2即可
Create repository->maven2(group)->my-public : 其中Group下的Available全部选择到右边或只选上面两项即可
这样就创建好自己的仓库了,如果要使用自己的仓库地址,只需要将上面的mirror的url指定为
http://localhost:8081/repository/my-public/
即可
8.发布自己的maven项目到私服
<distributionManagement>
<repository>
<id>my-project-releases</id>
<name>my-project</name>
<url>http://localhost:8081/repository/maven-public/</url>
</repository>
</distributionManagement>
发布命令:
mvn clean deploy -X -Dmaven.test.skip=true
然后就可以添加依赖了
9.如果公司通过代理上网给 Maven设置代理如下
在settings.xml 中添加代理设置
<proxies>
<proxy>
<id>company-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>88.110.0.120</host>
<port>8099</port>
</proxy>
</proxies>