搭建私有maven仓库

搭建之前

博主这里使用的是阿里云Centos7服务器。
博主环境如下:
jdk11、Centos7、nexus-3.16.1-02-unix

jdk安装

这里就直接过了。这个过于简单

maven仓库搭建

下载maven

博主这里疯狂拒绝连接,so,博主下载到本地,scp上去了

wget http://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.16.1-02-unix.tar.gz

解压

tar zxvf nexus-3.16.1-02-unix.tar.gz

配置

配置环境变量

sudo vi /etc/profile
source /etc/profile

export MAVEN_HOME=/home/codemperor/nexus-3.16.1-02
export PATH=$MAVEN_HOME:$PATH

启动

如果端口冲突,可以进入MAVEN_HOME/etc/nexus-default.properties 修改
进入maven的bin下面

./nexus start

如果报错:Detected execution as “root” user. This is NOT recommended!, 记得换用户哦:

useradd nexus
chown -R nexus:nexus /usr/local/nexus
su nexus
在这个用户下执行启动即可

访问

http://ip:8081 博主因为是内网搭建,所以用了负载均衡,不过还是8081啦
在这里插入图片描述

命令

//启动
nexus start

//停止
nexus stop

//重启
nexus restart

//查看状态
nexus status

修改admin密码

官网:https://support.sonatype.com/hc/en-us/articles/213467158-How-to-reset-a-forgotten-admin-password-in-Nexus-3-x
我们修改一下admin密码,然后我们创建一个其他的user,方便做权限管理
第一步:进入OrientDB控制台

linux: java -jar ./lib/support/nexus-orient-console.jar
win: java -jar lib\support\nexus-orient-console.jar
mac: .install4j/jre.bundle/Contents/Home/jre/bin/java -jar ./lib/support/nexus-orient-console.jar

第二步:进入数据库

connect plocal:/home/nexus/sonatype-work/nexus3/db/security admin admin

第三步:重置密码

update user SET password="这里是你要修改的密码" UPSERT WHERE id="admin"

maven仓库的使用

maven打包

将你的项目打成可执行jar,在pom中加入:

<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>upload.Boot</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后执行

mvn clean package -DskipTests

打出来有两个jar,我们使用with-dependencies 这个是把附带的所有第三方jar全部打进去了

上传maven仓库

登录我们的maven首页,然后点击上传
在这里插入图片描述
在这里插入图片描述

确定即可

修改pom

在pom中加入

<repositories>
        <repository>
            <id>nexus</id>
            <name>maven-public</name>
            <url>http://maven地址/repository/maven-public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

引入你刚才上传的jar的pom就ok啦

通过deploy:deploy上传

首先,我们在需要达成jar的pom中加入:

<distributionManagement>
        <repository>
            <!--此id要与setting.xml里面server的id对应-->
            <id>releases</id>
            <name>releases Repository</name>
            <url>http://x.x.x.x/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>snapshots</name>
            <url>http://x.x.x.x/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

然后在你的settings.xml中的中加入:

<servers>
	<server>
	        <id>releases</id>
	        <username>账</username>
	        <password>密码</password>
	    </server>
	    <server>
	        <id>snapshots</id>
	        <username>账号</username>
	        <password>密码</password>
	    </server>
</servers>

然后执行mvn deploy

搞定收工~

推荐一些文章:

https://www.cnblogs.com/2YSP/p/9533506.html
https://blog.csdn.net/u013887008/article/details/79429973
https://www.cnblogs.com/sxdcgaq8080/p/7583767.html
打包:https://www.cnblogs.com/sxdcgaq8080/p/8399854.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值