推荐通过maven配置,即第一种

通过maven上传

maven setting

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  5. <pluginGroups>
  6. </pluginGroups>
  7. <proxies>
  8. </proxies>
  9. <servers>
  10. <server>
  11. <id>nexus-releases</id>
  12. <username>admin</username>
  13. <password>admin123</password>
  14. </server>
  15. <server>
  16. <id>nexus-snapshots</id>
  17. <username>admin</username>
  18. <password>admin123</password>
  19. </server>
  20. </servers>
  21. <mirrors>
  22. <mirror>
  23. <id>maven-public</id>
  24. <name>maven-public</name>
  25. <url>http://192.168.1.2:8081/repository/maven-public/</url>
  26. <mirrorOf>central</mirrorOf>
  27. </mirror>
  28. </mirrors>
  29. <profiles>
  30. <profile>
  31. <id>maven-public</id>
  32. <repositories>
  33. <repository>
  34. <id>nexus-releases</id> <!--正式仓库id-->
  35. <!--name随便-->
  36. <name>Nexus Release Snapshot Repository</name>
  37. <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
  38. <url>http://192.168.1.2:8081/repository/maven-releases/</url>
  39. <releases>
  40. <enabled>true</enabled>
  41. </releases>
  42. <snapshots>
  43. <enabled>false</enabled>
  44. </snapshots>
  45. </repository>
  46. <repository>
  47. <id>nexus-snapshots</id>
  48. <url>http://192.168.1.2:8081/repository/maven-snapshots/</url>
  49. <releases>
  50. <enabled>false</enabled>
  51. </releases>
  52. <snapshots>
  53. <enabled>true</enabled>
  54. </snapshots>
  55. <updatePolicy>always</updatePolicy>
  56. </repository>
  57. </repositories>
  58. <pluginRepositories> <!--插件仓库地址,各节点的含义和上面是一样的-->
  59. <pluginRepository>
  60. <id>nexus-releases</id>
  61. <name>Nexus Release Snapshot Repository</name>
  62. <url>http://192.168.1.2:8081/repository/maven-releases/</url>
  63. <releases>
  64. <enabled>true</enabled>
  65. </releases>
  66. <snapshots>
  67. <enabled>true</enabled>
  68. </snapshots>
  69. </pluginRepository>
  70. <pluginRepository>
  71. <id>nexus-snapshots</id>
  72. <url>http://192.168.1.2:8081/repository/maven-snapshots/</url>
  73. <releases>
  74. <enabled>true</enabled>
  75. </releases>
  76. <snapshots>
  77. <enabled>true</enabled>
  78. </snapshots>
  79. <updatePolicy>always</updatePolicy>
  80. </pluginRepository>
  81. </pluginRepositories>
  82. </profile>
  83. </profiles>
  84. <!--激活配置-->
  85. <activeProfiles>
  86. <activeProfile>maven-public</activeProfile> <!--profile下的id-->
  87. </activeProfiles>
  88. </settings>

父pom

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.wd.cloud</groupId>
  6. <artifactId>api-root</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <packaging>pom</packaging>
  9. <name>api-root</name>
  10. <description>微服务根POM</description>
  11. <modules>
  12. <module>api-feign</module><!--内部互调接口定义-->
  13. <module>api-gateway</module><!--api网关-->
  14. <module>config-server</module><!--配置中心-->
  15. <module>discovery</module><!--服务注册中心-->
  16. <module>auth-server</module><!--鉴权服务-->
  17. <module>doc-delivery</module><!--文献传递服务-->
  18. <module>commons</module><!--提取的公共方法和类-->
  19. </modules>
  20. <distributionManagement>
  21. <!-- 两个ID必须与 setting.xml中的<server><id>nexus-releases</id></server>保持一致-->
  22. <repository>
  23. <id>nexus-releases</id>
  24. <name>Nexus Release Repository</name>
  25. <url>http://192.168.1.2:8081/repository/maven-releases/</url>
  26. </repository>
  27. <snapshotRepository>
  28. <id>nexus-snapshots</id>
  29. <name>Nexus Snapshot Repository</name>
  30. <url>http://192.168.1.2:8081/repository/maven-snapshots/</url>
  31. </snapshotRepository>
  32. </distributionManagement>
  33. </project>

common 类pom

  1. <build>
  2. <plugins>
  3. <!--避免没有main报错-->
  4. <plugin>
  5. <groupId>org.springframework.boot</groupId>
  6. <artifactId>spring-boot-maven-plugin</artifactId>
  7. <configuration>
  8. <skip>true</skip>
  9. </configuration>
  10. </plugin>
  11. <!--不上传到私服-->
  12. <plugin>
  13. <groupId>org.apache.maven.plugins</groupId>
  14. <artifactId>maven-deploy-plugin</artifactId>
  15. <configuration>
  16. <skip>true</skip>
  17. </configuration>
  18. </plugin>
  19. </plugins>
  20. </build>

命令行方式

  1. mvn deploy:deploy-file \
  2. -Dfile=C:\Users\madman\Desktop\alipay-sdk-java20161121110022.jar \
  3. -Durl=http://192.168.1.142:8081/nexus/content/repositories/snapshots/ \
  4. -DrepositoryId=nexus-snapshots \
  5. -DpomFile=pom.xml

直接上传第三方jar包

有些时候,我们只有一个单独jar包,怎么上传呢?
参考:https://blog.csdn.net/Alice_qixin/article/details/78390192

1,登录web页面 http://192.168..:**/nexus/ 点击右上角登录。

maven私服-上传 - 图1

2、找到第三方jar包目录

maven私服-上传 - 图2

3、上传jar包

maven私服-上传 - 图3
maven私服-上传 - 图4

4、上传后查看结果

maven私服-上传 - 图5