之前有位大佬问我,他说有个第三方的Jar包,在idea导出库中使用,现在要部署上线测试,要如何导进去打包。
 我说,不用那么麻烦,搞个Nexus私服,将Jar上传上去,然后配置Maven的setting文件指向私服就可以了。
下面介绍Nexus的安装和配置使用。
 
 环境:
[root@localhost bin]# java -version
openjdk version "1.8.0_382"
OpenJDK Runtime Environment (build 1.8.0_382-b05)
OpenJDK 64-Bit Server VM (build 25.382-b05, mixed mode)
[root@localhost bin]# cat /proc/version
Linux version 3.10.0-1160.71.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Jun 28 15:37:28 UTC 2022
1、安装
下载安装包:
下载地址

创建目录:
 mkdir nexus
移动压缩包:
mv nexus-3.62.0-01-unix.tar.gz  ./nexus
解压:
tar -xvf nexus-3.62.0-01-unix.tar.gz

 创建目录:
mkdir /usr/local/nexus
移动解压后的文件到新建的目录:
mv nexus-3.62.0-01 /usr/local/nexus/
切换到bin目录:
/usr/local/nexus/nexus-3.62.0-01/bin

编辑配置文件nexus.rc:
run_as_user="root"
启动nexus:
./nexus run &

 访问:http://192.168.213.5:8081/

登录:
 
 提示登录密码在:/usr/local/nexus/sonatype-work/nexus3/admin.password
点击左侧的browse,有各种repository的type:
- Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的所有仓库资源,访问顺序取决于配置顺序3.x默认Releases,Snapshots,Central,可在web页面配置在web界面点开
- Hosted:私有仓库,专门用来存储我们自己生成的jar文件
- Snapshots:本地项目的快照仓库
- Releases: 本地项目发布的正式版本
- Proxy:公网上发布的jar 例如:spring
- Central:中央仓库

配置maven的setting.xml:
在maven的setting.xml文件中配置私服配置,这种方式配置后所有本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置
<?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">
    
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
    
    <mirrors>
        
        <mirror>
            <id>nexus-releases</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/groups/public/</url>
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>
        <mirror>
            <id>nexus-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>                            
                <repository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-snapshots</id>
                    <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>nexus-snapshots</id>
                <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>				
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>nexus</activeProfile>
        <!--<activeProfile>dev</activeProfile>-->
    </activeProfiles>
</settings>




















