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包了
如在linux下,進入nexus-2.4.0-09\bin目錄,執行nexus start即可啓動
點擊右上角Log In,使用默認用戶admin/admin123即可登錄
maven客戶端配置遠程私服
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>
<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
<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>