linux下maven私服nexus搭建及配置


安裝

1.下載nexus-3.13.0-01-unix.tar.gz到/user/lcoal/src目錄

nexus3需要jdk8

2.解壓縮

nexus的工作目錄默認為sonatype-work,路徑與nexus安裝目錄同級,所以在外邊添加一層父目錄
mkdir /usr/local/nexus
tar -xzvf nexus-3.13.0-01-unix.tar.gz
mv nexus-3.13.0-01 /usr/local/nexus

3.編輯配置,編輯nexus.vmoptions

cd /usr/local/nexus-3.13.0-01/bin
vim nexus.vmoptions
vm參數修改為
-Xms256M
-Xmx256M
-XX:MaxDirectMemorySize=512M
Nexus默認的端口是8081,可以在etc/nexus-default.properties配置中修改。

4.啟動

cd /usr/local/nexus-3.13.0-01/bin
./nexus start
查看日志
tail -f /usr/local/nexus/sonatype-work/nexus3/log/nexus.log

5.瀏覽器打開管理頁面

http://ip:8081/
用戶名:admin
密碼:admin123

nexus配置

1.創建用戶

2.創建倉庫

默認倉庫介紹
1)maven-central: maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar
2)maven-releases: 私庫發行版jar
3)maven-snapshots:私庫快照(調試版本)jar
4)maven-public: 倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml中使用。
Nexus默認的倉庫類型有以下四種:(上面的名字可以隨便取,關鍵是它對應的是什么倉庫類型)
1)group(倉庫組類型):又叫組倉庫,用於方便開發人員自己設定的倉庫;
2)hosted(宿主類型):內部項目的發布倉庫(內部開發人員,發布上去存放的倉庫);
3)proxy(代理類型): 從遠程中央倉庫中尋找數據的倉庫(可以點擊對應的倉庫的Configuration頁簽下Remote Storage Location屬性的值即被代理的遠程倉庫的路徑);
4)virtual(虛擬類型): 虛擬倉庫(這個基本用不到,重點關注上面三個倉庫的使用);
Policy(策略):表示該倉庫為發布(Release)版本倉庫還是快照(Snapshot)版本倉庫;

主要創建3個倉庫
proxy倉庫 作用是去遠程拉取jar包
hosted倉庫 作用是存放本地上傳的三方jar包
group倉庫 作用是將上面來個放到這個組里,進行統一管理

創建proxy倉庫
類型maven2(proxy),proxy地址為阿里雲倉庫地址http://maven.aliyun.com/nexus/content/groups/public

創建兩個hosted倉庫:release,snaphost
類型為maven2(hosted)

創建group
類型為maven2(group),包含上面三個創建的倉庫

maven配置

setting.xml配置

<?xml version="1.0"?>
<settings>
	<localRepository>/Users/liufq/.m2/repository</localRepository><!--需要改成自己的maven的本地倉庫地址 -->
	<servers>
		<server>
			<!--jar上傳時候進行的驗證,id對應的pom中distributionManagement配置的id -->
			<id>releases</id>
			<username>xy</username>
			<password>xy</password>
		</server>
		<server>
			<id>snapshots</id>
			<username>xy</username>
			<password>xy</password>
		</server>
	</servers>

	<mirrors>
		<mirror>
			<id>nexus</id>
			<name>nexus</name>
			<!--鏡像采用配置好的組的地址 -->
			<url>http://192.168.1.102:8081/repository/xy-group/</url>
			<mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>

	<profiles>
		<profile>
			<id>jdk-1.8</id>
			<activation>
				<activeByDefault>true</activeByDefault>
				<jdk>1.8</jdk>
			</activation>
			<properties>
				<maven.compiler.source>1.8</maven.compiler.source>
				<maven.compiler.target>1.8</maven.compiler.target>
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
			</properties>
		</profile>

		<profile>
			<id>nexus-repo</id>
			<!-- 遠程倉庫列表 -->
			<repositories>
				<repository>
					<id>nexus-repo</id>
					<name>Nexus Central</name>
					<!-- 指向鏡像的URL -->
					<url>http://192.168.1.102:8081/repository/xy-group/</url>
					<layout>default</layout>
					<!-- 表示可以從這個倉庫下載releases版本的構件 -->
					<releases>
						<enabled>true</enabled>
					</releases>
					<!-- 表示可以從這個倉庫下載snapshot版本的構件 -->
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<!-- 插件倉庫列表 -->
			<pluginRepositories>
				<pluginRepository>
					<id>nexus-repo</id>
					<name>Nexus Central</name>
					<url>http://192.168.1.102:8081/repository/xy-group/</url>
					<layout>default</layout>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
					<releases>
						<enabled>true</enabled>
					</releases>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>

	<activeProfiles>
		<!--需要激活 <profile>中的ID才生效 -->
		<activeProfile>nexus-repo</activeProfile>
		<activeProfile>jdk-1.8</activeProfile>
	</activeProfiles>

</settings>  

pom.xml配置

<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.pt</groupId>
	<artifactId>pt-parent</artifactId>
	<version>1.0.0-RELEASE</version>
	<packaging>pom</packaging>
	<name>pt-parent</name>

	<properties>
		<project.groupId>com.pt</project.groupId>
		<project.version>1.0.0-RELEASE</project.version>
		<junit.version>4.12</junit.version>
		<spring.version>4.3.9.RELEASE</spring.version>
		<logback.version>1.2.3</logback.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<modules>
		<module>pt-utils</module>
		<module>pt-db</module>
		<module>pt-seqGenerator</module>
		<module>pt-msg</module>
	</modules>

	<dependencyManagement>
		...
	</dependencyManagement>

    <!-- 打包上傳配置 -->
	<distributionManagement>
		<repository>
			<id>releases</id>
			<name>Internal Releases</name>
			<url>http://192.168.1.102:8081/repository/xy-release/</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<name>Internal snapshots</name>
			<url>http://192.168.1.102:8081/repository/xy-snaphost/</url>
		</snapshotRepository>
	</distributionManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>3.1.0</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>attach-sources</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<version>2.10.4</version>
				<configuration>
					<encoding>UTF-8</encoding>
					<aggregate>true</aggregate>
					<charset>UTF-8</charset>
					<docencoding>UTF-8</docencoding>
				</configuration>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-deploy-plugin</artifactId>
				<version>2.8.2</version>
				<executions>
					<execution>
						<id>deploy</id>
						<phase>deploy</phase>
						<goals>
							<goal>deploy</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

</project>

測試

下載jar包
mvn clean install -Dmaven.test.skip=true 
打包上傳
mvn clean deploy -Dmaven.test.skip=true 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM