1. 程式人生 > 其它 >搭建私服nexus win環境 以nexus-3.14.0-04-win64為例

搭建私服nexus win環境 以nexus-3.14.0-04-win64為例

執行

  1. 以管理員身份執行cmd ,使用nexus.exe /run 命令啟動nexus服務
  2. 開啟瀏覽器訪問訪問 http://localhost:8081地址,登入
    預設的使用者名稱和密碼分別是:admin/amdin123

新增一個阿里雲的代理倉庫

倉庫url為http://maven.aliyun.com/nexus/content/groups/public

在public組裡將這個aliyun-proxy倉庫加入,排在maven-central之前

修改maven配置setting.xml檔案

<?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">
  <!-- localRepository
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
    <localRepository>D:\Maven\repository</localRepository>
-->

  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
	<server>
		<id>nexus</id>  
		<username>admin</username>
		<password>admin123</password>
	</server>
	
	<server>
		<id>maven-public</id>  
		<username>admin</username>
		<password>admin123</password>
	</server>
  </servers>
  
  <mirrors>
	<mirror>
      <id>nexus</id>
      <url>http://172.16.81.154:8081/repository/maven-public/</url><!-- 私服倉庫地址 -->
      <mirrorOf>*</mirrorOf>
	</mirror>
  </mirrors>

  <profiles>
	<profile>
      <repositories>
        <repository>
          <id>releases</id><!--正式倉庫id-->
		  <name>Releases</name>
          <url>http://172.16.81.154:8081/repository/maven-central/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories><!--外掛倉庫地址-->
        <pluginRepository>
          <id>releases</id>
		   <name>Releases</name>
          <url>http://172.16.81.154:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
	  <!-- 配置遠端釋出到私服,mvn deploy -->
	  <distributionManagement>  
	    <repository>    
	        <id>maven-releases</id>
	        <name>Nexus Release Repository</name>
	        <url>http://172.16.81.154:8081/repository/maven-releases/</url> 
	    </repository>  
	    <snapshotRepository>  
	         <id>maven-snapshots</id>
	         <name>Nexus Snapshot Repository</name> 
	        <url>http://172.16.81.154:8081/repository/maven-snapshots/</url>  
	    </snapshotRepository> 
	  </distributionManagement>
	  
    </profile>
  </profiles>
  
  <activeProfiles>
	<activeProfile>public</activeProfile>
  </activeProfiles>
</settings>

maven pom檔案

與setting中的 id一致

<repositories>
	<repository>
		<id>maven-public</id>
		<name>maven2</name>
		<url>http://172.16.81.154:8081/repository/maven-public/</url>
	</repository>
</repositories>

上傳jar

方式一:使用nexus自帶操作介面

方式二:使用命令

mvn deploy:deploy-file -DgroupId=xxx.xxx -DartifactId=xxx -Dversion=0.0.2 -Dpackaging=jar -Dfile=D:\xxx.jar -Durl=http://xxx.xxx.xxx.xxx:8081/repository/3rdParty/ -DrepositoryId=3rdParty

-DgroupId 為上傳的jar的groupId-DartifactId 為上傳的jar的artifactId-Dversion 為上傳的jar的需要被依賴的時候的版本號-Dpackaging為jar,-Dfile為jar包路徑-Durl 為要上傳的路徑,可以通過以下方式獲取到

mvn deploy:deploy-file -DgroupId=com.dingtalk.open -DartifactId=taobao-sdk-java-auto -Dversion=1479188381469-20210610 -Dpackaging=jar -Dfile=I:\taobao-sdk-java-auto-1479188381469-20210610.jar -Durl=http://172.16.81.154:8081/repository/maven-releases/ -DrepositoryId=maven-releases