Nexus OSS私服倉庫的安裝和配置以及與Maven整合配置

1、到官網(http://www.sonatype.org/nexus/)下載最新的開源版本,一般有兩種,war包和bundle包,明顯,war必須放在web容器下,而bundle已經包含了一個Jetty容器,啓動就可以運行。

2、默認的監聽地址爲:http://your-server:8081/nexus

3、Nexus的默認登錄帳號爲:admin:admin123


4、配置Maven與nexus的連接

a、直接配置在項目的Pom文件中;

<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>
	<!-- 略 -->
	<modules>
		<!-- 略 -->
	</modules>

	<dependencyManagement>
		<!-- 略 -->
	</dependencyManagement>

	<!-- Environment Settings -->
	<distributionManagement>
		<repository>
			<id>nexus-releases</id>
			<name>Releases Repository of XXX</name>
			<url>http://your-server/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus-snapshots</id>
			<name>Snapshots Repository of XXX</name>
			<url>http://your-server/nexus/content/repositories/snapshots</url>
		</snapshotRepository>
	</distributionManagement>
	<repositories>
		<repository>
			<id>nexus-public</id>
			<name>Public Repository of XXX</name>
			<url>http://your-server/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>
	<!-- Environment Settings -->
</project>

該配置完成了java構件的下載倉庫(repostories)和發佈倉庫(distributionManagement)。

值得注意的是,發佈構建一般需要帳號和密碼,需要配置在settings.xml文件中,在後面會提到。

b、配置在Maven的配置中,有兩處:(1)Maven程序的conf目錄下的settings.xml中,作用於全局用戶;(2)在用戶目錄的.m2文件夾(隱藏文件)下的settings.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">
        <mirrors>
                <mirror>
                        <id>nexus-public</id>
                        <name>Nexus Repository of XXX</name>
                        <url>http://your-server/nexus/content/groups/public/</url>
                        <mirrorOf>central</mirrorOf>
                </mirror>
        </mirrors>
        <servers>
                <!-- 略 -->
        </servers>
</settings>

該配置實際上實現了中央庫的鏡像,因爲在Pom文件不做任何配置的情況下,默認是使用id爲central的Maven中央庫進行配置的。

注意,該配置只取代了pom中的下載倉庫。

5、配置構件發佈的帳號與密碼

在settings.xml中配置,這個文件在第4點中有提到,配置如下:

<?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">
        <servers>
                <server>
                        <id>nexus-releases</id>
                        <username>developer</username>
                        <password>123456</password>
                </server>
                <server>
                        <id>nexus-snapshots</id>
                        <username>developer</username>
                        <password>123456</password>
                </server>
        </servers>
</settings>

注意:id必須與Pom文件中配置的id一致。


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