Install nexus on linux and publish jar to private server

Install nexus on linux and publish jar to private server

1. Install jdk1.8 (jdk is not installed)

#使用yum安装
yum install -y java-1.8.0-openjdk-devel.x86_64
#输入java -version查看已安装的jdk版本(输入命令javac看是否报错)
#安装目录  /usr/lib/jvm目录下找
#输入命令vi /etc/profile,打开环境变量配置文件
#在文件底部输入以下信息,并保存
JAVA_HOME=/usr/lib/jvm/.........../jdk1.8.0_131
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
#输入命令source /etc/profile,刷新环境变量配置文件使其立刻生效
#还有一步操作最好做一下。建一个/usr/bin/java的java的超链接。
ln -s /usr/lib/jvm/.........../jdk1.8.0_131/bin/java /usr/bin/java

Why build this hyperlink, because some self-registered linux services (such as services registered by springboot's jar), use java from the /usr/bin/java path by default, and this hyperlink will be created automatically when yum is installed. If you download the package and install it yourself, you need to create this hyperlink manually

2. Install nexus

#进入/usr/local目录创建一个nexus文件夹
cd /usr/local
mkdir nexus
cd nexus
tar -zxvf nexus-3.19.1-01-unix.tar.gz
#解压出来有两个文件夹:
这是程序目录:nexus-3.19.1-01
这是仓库目录:sonatype-work
#由于目录 sonatype-work 以后是做仓库用的,会存储很多 jar,所以这个目录一定要放在磁盘空间大的区内
#进入nexus安装的bin目录
cd /usr/local/nexus/nexus-3.19.1-01/bin
#执行启动命令
./nexus start
#有时启动成功后,CPU会异常飙高,这是可以修改nexus的启动vm配置
vim nexus.vmopt
#修改这三个配置为:
-Xms512m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m
#若出现worning(不能用root启动),则修改nexus启动文件,在文件中的run_as_root=true改为false
run_as_root=false
#然后重新启动nexus
#访问nexus(http://ip:8081)
#初次登录密码在sonatype-work文件夹下的admin.password(就是一串字符串,直接复制就可以,登陆成功后会提示你修改密码)

3. Publish the local jar to the private server

<!--在本地maven的配置文件中的<servers>标签下 ,添加连接私服的账号密码和ID(我用的是Idea自带的maven)配置如下-->
<servers>
    <server>
      <id>maven-public</id>
      <username>admin</username>
      <password>admin</password>
    </server>
	<server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>admin</password>
    </server>
	<server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin</password>
    </server> 
</servers>
<repositories>
<repository>
 <id>maven-public</id>
   <url>http://120.26.41.210:8081/repository/maven-public/</url>
	 <releases>
		<enabled>true</enabled>
	 </releases>
	 <snapshots>
		<enabled>true</enabled>
	 </snapshots>
</repository>
<repository>
 <id>maven-releases</id>
    <url>http://120.26.41.210:8081/repository/maven-releases/</url>
	  <releases>
		<enabled>true</enabled>
	  </releases>
	  <snapshots>
		<enabled>false</enabled>
	  </snapshots>
</repository>
<repository>
 <id>maven-snapshots</id>
    <url>http://120.26.41.210:8081/repository/maven-snapshots/</url>
	 <releases>
		<enabled>false</enabled>
	 </releases>
	 <snapshots>
		<enabled>true</enabled>
	 </snapshots>
</repository>
</repositories>
<pluginRepositories>
	<pluginRepository>
		<id>maven-public</id>
		<url>http://120.26.41.210:8081/repository/maven-public/</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</pluginRepository>
	<pluginRepository>
		<id>maven-releases</id>
		<url>http://120.26.41.210:8081/repository/maven-releases/</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</pluginRepository>
	<pluginRepository>
		<id>maven-snapshots</id>
		<url>http://120.26.41.210:8081/repository/maven-snapshots/</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</pluginRepository>
<!--在Idea中POM文件中添加如下配置(这里的url,可以通过 Nexus 后台上仓库页面的 cpoy 按钮自动复制得到)-->
<!-- 发布maven私服 -->
<distributionManagement>
    <repository>
        <id>maven-public</id>
        <name>maven-public</name>
        <url>http://120.26.41.210:8081/repository/maven-public/</url>
    </repository>
    <snapshotRepository>
        <id>maven-snapshots</id>
        <name>maven-snapshots</name>
        <url>http://120.26.41.210:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
<!--将nexus私服配置为远程仓库-->
<packaging>jar</packaging>

Then execute maven's depoly deployment plug-in to publish, and it will be automatically published to the nexus private server. (Note: The premise is that the current build is a maven project)

Guess you like

Origin blog.csdn.net/weixin_48453772/article/details/123710727