Skip to content

上传至本地仓库

shell
mvn install:install-file -Dfile=jar包路径(绝对路径|相对路径) -DgroupId=com.xxx -DartifactId=xxx -Dversion=xxx -Dpackaging=xxx(通常为jar)

上传至私服

  1. 正确配置Maven的settings.xml文件,以便正确配置私服的认证和URL

    • 添加私服链接

      xml
      <mirror>
          <id>nexus</id>
          <name>nexus repository</name>
          <url>http://192.168.122.51:9111/repository/maven-public/</url>
          <mirrorOf>central</mirrorOf>
      </mirror>
    • 添加私服各环境账号密码

      xml
      <server>  
          <id>nexus</id>  
          <username>admin</username>  
          <password>xxxx</password>  
      </server>  
      <server>  
          <id>nexus-releases</id>  
          <username>admin</username>  
          <password>xxxx</password>  
      </server>  
      <server>  
          <id>nexus-snapshots</id>  
          <username>admin</username>  
          <password>xxxx</password>  
      </server>
  2. 方式一:执行下面命令将jar上传至私服

    shell
    mvn deploy:deploy-file -Dfile=jar包路径 -DgroupId=com.xxx -DartifactId=xxx -Dversion=xxx -Dpackaging=jar -DgeneratePom=true -Durl=http://xxxx.com/repository/maven-releases/(私服URL) -DrepositoryId=releases(私服ID)
  3. 方式二:使用idea插件上传

    • pom文件中添加私服链接

      xml
      <distributionManagement>
          <repository>
              <id>nexus-releases</id>
              <name>releases</name>
              <url>http://192.168.122.51:9111/repository/maven-releases/</url>
          </repository>
      </distributionManagement>
    • pom文件中引入上传工具插件

      xml
      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-deploy-plugin</artifactId>
                  <version>2.8.2</version>
              </plugin>
          </plugins>
      </build>
    • 然后点击右侧Lifecycle中的deploy进行部署即可

MIT版权,未经许可禁止任何形式的转载