一、我们为什么要使用私服?
主要有两个目的:第一个,避免直接从远程仓库下载我们在自己的项目中需要的构件;第二个,部署我们自己的公共构件到一个私有的仓库(我们自己的私服),方便在各个项目中共享。
二、私服环境搭建
这里我们基于Linux环境搭建。
第一步:下载nexus包(wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz
);
第二步:解压(tar -xzvf nexus-2.11.2-03-bundle.tar.gz -C nexus);
第三步:启动(bin/nexus start);
第四步:访问(http://116.62.40.32:8081/nexus),启动后的默认端口是8081;注意,这里的访问地址直接用了IP地址,如果想通过域名访问,我们可以增加Nginx配置来实现。
server {
listen 80;
server_name 自己设置的域名;
#charset koi8-r;
access_log 访问日志目录 main;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 64m;
client_body_buffer_size 10M;
proxy_buffers 32 4k;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://127.0.0.1:8081;//代理的访问路径
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
三、私服使用
1.默认登录账号:用户名-admin,密码-admin123
2.创建自己的仓库;
3.让自己的每一个项目都使用私服下载构件——修改Maven的settings.xml文件(完整的配置)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/Users/wuhoujian/Documents/m2/repository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>jhzz-releases</id>
<username>xxx</username>
<password>xxx</password>
</server>
<server>
<id>jhzz-snapshots</id>
<username>xxx</username>
<password>xxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>jhzz-nexus</id>
<mirrorOf>*</mirrorOf>
<name>MyRepository</name>
<!--私服仓库地址-->
<url>自己的私服地址/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jhzz-nexus</id>
<repositories>
<repository>
<id>central</id>
<name>MyRepository</name>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>jhzz-nexus</activeProfile>
</activeProfiles>
</settings>
4.如何部署自己的构件到私服?
第一步:settings.xml添加权限认证配置,否则无法完成构件的部署;
第二步:修改项目的pom.xml文件;
<distributionManagement>
<repository>
<id>jhzz-releases</id>
<name>JHZZ Releases Repository</name>
<url>http://nexus.jihezhizao.com/nexus/content/repositories/jhzz-releases/</url>
</repository>
<snapshotRepository>
<id>jhzz-snapshots</id>
<name>JHZZ Snapshots Repository</name>
<url>http://nexus.jihezhizao.com/nexus/content/repositories/jhzz-snapshots/</url>
</snapshotRepository>
</distributionManagement>
第三步:部署构件到私服;
简单部署:mvn clean deploy
复杂部署:mvn clean source:jar deploy -D maven.test.skip=true(同时部署构件和对应的源码,这样我们在项目中引入自己部署的构件,便可以查看源码)
相关推荐
Windows 下Nexus搭建Maven私服 Windows 下Nexus搭建Maven私服
关于使用Nexus搭建Maven私服的开发文档。新手了解一下。
Nexus搭建Maven私服 +maven安装步骤
linux下搭建内网maven私服
Maven Nexus 私服搭建 从零开始,资源下载、安装指导、开发配置说明
搭建maven私服的软件,包括maven版本3.5.3,nexus版本3.12.1
详细的使用Nexus搭建Maven私服的步骤指导
使用Nexus1.8搭建MAVEN私服详细步骤,以及在网页上上传JAR包
附件是自己使用docker在内网和外网搭建Maven私服Nexus3所总结的文档,通过该文档可以在内网搭建属于自己的nexus私服,提高自己的生产力。
在CentOS7上用Nexus3搭建Maven私服。 一、需要的环境 CentOS 7里需要安装jdk8和Maven3,具体的安装步骤可以百度一下。 二、需要的包 需要nexus3的安装包,官网上https://www.sonatype.com/download-oss-sonatype...
maven使用及Nexus搭建Maven私服
1、搭建阿里云maven私服仓库 2、本地jar手动上传到阿里云maven私服仓库 3、本地项目通过idea自动上传到阿里云maven私服仓库 4、从阿里云私服仓库拉取maven依赖的jar包
maven私服搭建文档里简单介绍了maven私服的搭建及配置
提供了基于Nexus搭建Maven私服所需要的一切资源和个人经验,搭建后可maven deploy 上传自己的jar包。别人如何在自己的maven项目中引用我将单独再上传一份。
配置Maven私服时,需要修改Maven的默认配置文件,此文件已经配置好Maven私服模板,只需要修改IP和对应的端口号即可
该压缩文件包含nexus-3.37.3-02-win64.zip、如何修改远程仓库地址.docx、如何在Windows下搭建Maven私服.docx和视频地址.txt等四个文件,主要介绍了如何搭建Maven私服,视频教程:...
搭建Maven私服,并配置Nexus环境.rar
阿里云ECSlinux服务器搭建和maven私服仓库技术文档.zip