【Maven】如何把第三方jar包上传到私有仓库或者是maven私服

说明

maven是个非常好用的东西,但是前提是有外网才能随心所欲。如果是内网项目呢,那就需要我们自己搭建一个私有仓库了,具体怎么搭建百度上有一大堆的资料,这里就不讲解了。这里我们主要说一下当我们需要上传私有jar包的时候,该如何上传?

上传jar到私有仓库
使用搭建的私有仓库的页面地址上传

这种上传也是可以的,但是过程稍麻烦一点

使用maven命令上传

使用maven命令,首先配置好maven的settings配置文件以及mavevn项目的pom.xml

  1. 找到settings里面的localRepository节点位置,添加localRepository节点配置,这里配置的是从maven下载的jar存放的地方也就是本地仓库
    在这里插入图片描述
  2. 找到settings里面的servers节点位置,添加私服的账号和密码,这里的id为releases和snapshots,这个id你可以随便取只要和下面的配置一致即可,我这里代表的两个是私服的两个仓库
    在这里插入图片描述
  3. 找到settings里面的mirrors节点位置,配置仓库地址,这里的id和上面的一致
    在这里插入图片描述
  4. 找到settings里面的profiles节点位置,这里配置的要多一点,不用截图了
<profiles>
    <!--profile 节点可以配置多个 只要id不一样就可以 在下面的activeProfiles节点就可以选择活跃的profile节点-->
		<profile>
		  <id>dev</id>
          <repositories>
            <repository>
              <id>releases</id>
              <!--请输入你自己的地址-->
              <url>http://IP/repository/maven-public/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
            </repository>
			<repository>
              <id>snapshots</id>
              <!--请输入你自己的地址-->
              <url>http://IP/repository/maven-snapshots/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
            </repository>
          </repositories>
		  <pluginRepositories>
			<pluginRepository>
				<id>releases</id>
				<!--请输入你自己的地址-->
                <url>http://IP/repository/maven-snapshots/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
			<pluginRepository>
				<id>snapshots</id>
				<!--请输入你自己的地址-->
                <url>http://IP/repository/maven-snapshots/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		  </pluginRepositories>
		  

        </profile>
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
  1. 找到settings里面的activeProfiles节点位置,这里配置的是活跃的profile的地方。
    在这里插入图片描述
  2. 修改pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.xing</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>


    <distributionManagement>
        <!-- 这里写的就是你想上传的仓库,一般都是写一个第三方仓库 -->
        <!--<repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>http://10.33.66.159:8081/repository/maven-public/</url>
        </repository>-->
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshots Repository</name>
            <!-- 请填写你自己的仓库地址 -->
            <url>http://IP/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
</project>
  1. 使用命令maven clean deploy -U
    在这里插入图片描述

整个项目截图:
在这里插入图片描述

如有错误之处,请指正,不胜感激。如有疑惑,留言即可。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值