Nexus 搭建 使用

Nexus環境搭建
nexus是用來建立公司內部或社區內部的一個maven倉庫,可以供指定用戶羣體使用。


下載nexus

去官網下載相應的包,有bundle版本,還有war包版本,我選擇nexus-2.4.0-09-bundle.tar.gz,因爲它是用jdk1.6版本編譯的。如有需求,可自行到官網點我選擇相應版本,我用的版本請點擊下載


配置nexus

解壓nexus-2.4.0-09-bundle.tar.gz,應該獲得如下目錄結構: 
  • nexus-2.4.0-09是nexus服務主目錄
  • sonatype-work是真正的倉庫,包含了nexus的配置,如定時任務、用戶配置等
  • sonatype-work\nexus\storage用來存放所有jar包,可將maven的repository的jar包移植過來,就不需要重複下載jar包了
nexus配置文件爲nexus-2.4.0-09\nexus.properties,application-port指定部署端口,,application-host指定部署IP,
根據需要自行部署


安裝nexus服務

進入nexus-2.4.0-09\bin\jsw\windows-x86-64目錄,執行install-nexus.bat,便會將nexus作爲windows一個服務,接着執行start-nexus.bat啓動nexus服務,在瀏覽器地址欄輸入http://localhost:8090/nexus
啓動成功後打開主界面如下:



nexus支持如下命令: 
引用
nexus { console | start | stop | restart | status | dump }

如在linux下,進入nexus-2.4.0-09\bin目錄,執行nexus start即可啓動


點擊右上角Log In,使用默認用戶admin/admin123即可登錄


maven客戶端配置遠程私服

nexus鏡像使用步驟:打開maven的全局配置文件中(setting.xml)

1:在mirros節點添加
<mirror>
	<id>nexus</id>
	<name>ziwow nexus</name>
	<url>http://<Your Nexus IP>/nexus/content/groups/public</url>
	<mirrorOf>*</mirrorOf>
</mirror>



2:在profiles節點添加
<profile>
	<id>dev</id>
	<repositories>
		<repository>
			<id>central</id>
			<name>Public Repositories</name>
			<url>http://<Your Nexus IP>/nexus/content/groups/public</url>
			<layout>default</layout>
			<snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			</snapshots>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>central</id>
			<name>Public Repositories</name>
			<url>http://<Your Nexus IP>/nexus/content/groups/public</url>
			<layout>default</layout>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>
</profile>


3:在activeProfiles節點中添加如下節點
<activeProfiles>  
<activeProfile>dev</activeProfile>
</activeProfiles>



4:配置發佈構件用戶(如有需要)
<server>
<id>releases</id>
<username>xxxxx</username>
<password>111111</password>
</server>
<server>
<id>snapshots</id>
<username>yyyyy/username>
<password>111111</password>
</server> 


5:在項目pom文件中添加以下配置 
<project>
	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>nexus releases</name>
			<url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>nexus snapshot</name>
			<url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
</project>



6:發佈jar包到nexus命令
mvn clean deploy 

擴展:

如需指定項目資源文件編碼,將源代碼發佈到nexus,加入一下插件即可。
<project>
<build>
<plugins>
	<!-- 指定JDK編譯版本, 以及資源文件編碼 -->
	<plugin>
		<artifactId>maven-compiler-plugin</artifactId>
		<configuration>
			<source>1.6</source>
			<target>1.6</target>
			<encoding>UTF-8</encoding>
		</configuration>
	</plugin>
	<!-- 解決資源文件的編碼問題 -->
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-resources-plugin</artifactId>
		<configuration>
			<encoding>UTF-8</encoding>
			</configuration>
	</plugin>
	<!-- 打包源代碼成jar包 -->
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-source-plugin</artifactId>
		<executions>
			<execution>
				<id>attach-sources</id>
				<goals>
					<goal>jar</goal>
				</goals>
					</execution>
				</executions>
	</plugin>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId>
		<version>2.4.2</version>
		<configuration>
			<skipTests>true</skipTests>
		</configuration>
	</plugin>
	<!-- jetty 插件 -->
	<plugin>
		<groupId>org.mortbay.jetty</groupId>
		<artifactId>jetty-maven-plugin</artifactId>
		<version>8.1.8.v20121106</version>
	</plugin>
	<plugin>
		<artifactId>maven-assembly-plugin</artifactId>
	</plugin>
</plugins>
</build>
</project>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章