详解:使用nexus搭建个人私服,原来maven还可以这么玩!nexus网盘下载!

此篇内容记录如何使用nexus搭建个人maven私服,以及如何在IDEA中使用maven拉取或者上传个人jar包

最近在公司中有这么个事,有两套系统,其中一套是正常的主线任务,另一套是领导想做点扩展功能的支线任务。最后将第二套的代码以一个jar包的形式供主线任务调用。想着之前白嫖而且一直空置着的阿里云服务器,于是就准备搭一个私服让两个系统的联动起来,不用打一次jar包重新手动导一次的麻烦,so~废话不多说开始bb环节。

第一步 下载nexus包

因为是国外网站下载比较慢,这里附上我百度云里的nexus

nexus资源,提取密码是:hmuc

这里有对应mac,linux,windows的三个压缩包,大家自拿自取。

第二步 安装JDK

因为nexus需要java的运行环境,所以想使用nexus前提是已经具备了jdk的环境。
使用yum一键安装jdk1.8环境。
yum install java-1.8.0-openjdk-devel.x86_64

第三步 上传nexus文件到服务器

这里是使用xftp远程上传Linux服务器,方便快捷
阿里云工具

第三步 解压nexus

  1. 找到放nexus包的位置
  2. 使用命令
    tar -xzvf nexus-3.13.0-01-unix.tar.gz
    这里的nexus-3.13.0-01-unix.tar.gz是自己上传的文件
    解压后会有两个文件夹
    在这里插入图片描述
    nexus-3.19.1-01放的是可执行文件,运行环境
    sonatype-work放的是通用配置,运行数据等

配置nexus

进入到**/nexus-3.19.1-01/bin,能看到有一个nexus.vmoptions,使用编辑命令进去改一下参数。
`
在这里插入图片描述

vm参数修改为
-Xms256M
-Xmx256M
-XX:MaxDirectMemorySize=512M
Nexus默认的端口是8081,可以在etc/nexus-default.properties配置中修改。

在这里插入图片描述
这里如果不改,nexus很可能启动不了,或者启动超级慢。

运行nexus

进入/bin目录,使用命令
./nexus start
这样nexus就运行起来了。

登录nexus

这里需要放行nexus运行的端口,默认是8081。在阿里云服务器安全组里配置放行端口!
windows版本下的默认账户密码是:
admin
admin123
Linux版本下的默认账户密码需要去文件中找

找到sonatype-work/nexus/admin.password文件
使用命令cat admin.password瞄一眼这个文件
会看到一串貌似被加密过的字符串
密码
不要有任何怀疑,复制这一串子。
账户是admin,密码就是这一串。登录成功后会强制修改密码,这个文件随即也会被删除掉。

配置私服

在这里插入图片描述这里有被提前创建好的仓库,可以直接使用,当然也可以自己配置仓库。

在配置代理仓库时这里修改成阿里的镜像代理,不然依赖的下载速度可能会非常慢。
在这里插入图片描述
阿里的nexus代理地址:http://maven.aliyun.com/nexus/content/groups/public

配置完成后
在这里插入图片描述
这里的URL是后面需要配置在自己项目里的。

IDEA配置nexus

setting.xml配置

<?xml version="1.0"?>
<settings>
	<localRepository>/Users/liufq/.m2/repository</localRepository><!--需要改成自己的maven的本地仓库地址 -->
	<servers>
		<server>
			<!--jar上传时候进行的验证,id对应的pom中distributionManagement配置的id -->
			<id>releases</id>
			<username>xy</username>
			<password>xy</password>
		</server>
		<server>
			<id>snapshots</id>
			<username>xy</username>
			<password>xy</password>
		</server>
	</servers>

	<mirrors>
		<mirror>
			<id>nexus</id>
			<name>nexus</name>
			<!--镜像采用配置好的组的地址 -->
			<url>http://192.168.1.102:8081/repository/xy-group/</url>
			<mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>

	<profiles>
		<profile>
			<id>jdk-1.8</id>
			<activation>
				<activeByDefault>true</activeByDefault>
				<jdk>1.8</jdk>
			</activation>
			<properties>
				<maven.compiler.source>1.8</maven.compiler.source>
				<maven.compiler.target>1.8</maven.compiler.target>
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
			</properties>
		</profile>

		<profile>
			<id>nexus-repo</id>
			<!-- 远程仓库列表 -->
			<repositories>
				<repository>
					<id>nexus-repo</id>
					<name>Nexus Central</name>
					<!-- 指向镜像的URL -->
					<url>http://192.168.1.102:8081/repository/xy-group/</url>
					<layout>default</layout>
					<!-- 表示可以从这个仓库下载releases版本的构件 -->
					<releases>
						<enabled>true</enabled>
					</releases>
					<!-- 表示可以从这个仓库下载snapshot版本的构件 -->
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<!-- 插件仓库列表 -->
			<pluginRepositories>
				<pluginRepository>
					<id>nexus-repo</id>
					<name>Nexus Central</name>
					<url>http://192.168.1.102:8081/repository/xy-group/</url>
					<layout>default</layout>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
					<releases>
						<enabled>true</enabled>
					</releases>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>

	<activeProfiles>
		<!--需要激活 <profile>中的ID才生效 -->
		<activeProfile>nexus-repo</activeProfile>
		<activeProfile>jdk-1.8</activeProfile>
	</activeProfiles>

</settings>  

pom文件中配置

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.pt</groupId>
	<artifactId>pt-parent</artifactId>
	<version>1.0.0-RELEASE</version>
	<packaging>pom</packaging>
	<name>pt-parent</name>

	<properties>
		<project.groupId>com.pt</project.groupId>
		<project.version>1.0.0-RELEASE</project.version>
		<junit.version>4.12</junit.version>
		<spring.version>4.3.9.RELEASE</spring.version>
		<logback.version>1.2.3</logback.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<modules>
		<module>pt-utils</module>
		<module>pt-db</module>
		<module>pt-seqGenerator</module>
		<module>pt-msg</module>
	</modules>

	<dependencyManagement>
		...
	</dependencyManagement>

    <!-- 打包上传配置 -->
	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>Internal Releases</name>
			<url>http://192.168.1.102:8081/repository/xy-release/</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>Internal snapshots</name>
			<url>http://192.168.1.102:8081/repository/xy-snaphost/</url>
		</snapshotRepository>
	</distributionManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.1.0</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>attach-sources</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<version>2.10.4</version>
				<configuration>
					<encoding>UTF-8</encoding>
					<aggregate>true</aggregate>
					<charset>UTF-8</charset>
					<docencoding>UTF-8</docencoding>
				</configuration>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-deploy-plugin</artifactId>
				<version>2.8.2</version>
				<executions>
					<execution>
						<id>deploy</id>
						<phase>deploy</phase>
						<goals>
							<goal>deploy</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

</project>

至此,nexus的配置完成!使用deploy命令即可将项目打包并将依赖上传至自己的nexus私服上去了!
maven命令

可能遇到的问题

可能会有小伙伴的依赖无法拉取等问题,大家进自己仓库把一些废弃依赖删除掉。
方法:今日仓库目录,搜索last,将检索到的所有依赖全部删除,因为没有下载完成的废弃依赖都是以lastupdate结尾的,这样再去拉取依赖一般没啥问题。
在这里插入图片描述

本篇文章完结,写的不好的地方大家多多包涵!
希望可以帮助到求知的你~

1+1=3!
如果有不明白的可以和我一起探讨交流哦,一起进步联系方式在主页上

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值