Nexus下載地址:https://www.sonatype.com/download-oss-sonatype
選擇相應的版本下載后,本人下載的是nexus-2.12.0-01-bundle.zip版本。nexus默認是和jetty集成的,如果要在Tomcat環境下使用,則按照如下步驟進行配置即可:
1,解壓文件后后得到兩個文件夾,[nexus-2.12.0-01]及[sonatype-work],[nexus-2.12.0-01]文件夾看到他的結構類似於Tomcat服務器。

將這兩個文件夾復制到一個目錄下,可以不用在Tomcat的webapps目錄下也行。本人是在webapps下面創建了一個Nexus的文件夾,並將這兩個文件復制到里面,如:F:\Tomcat8\apache-tomcat-8.5.9\webapps\Nexus。
2.把nexus-2.12.0-01\lib文件夾下面的除了javax.servlet*.jar及jetty*jar的所有jar包文件復制到nexus-2.12.0-01\nexus\WEB-INF\lib下面。
3.修改nexus-2.12.0-01\nexus\WEB-INF\classes\nexus.properties文件修改:nexus-work=F:/Tomcat8/apache-tomcat-8.5.9/webapps/Nexus/sonatype-work/nexus,注意斜桿的方向。
4.修改Tomcat的server.xml文件,在Host節點內添加Context節點,修改后如下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="F:\Tomcat8\apache-tomcat-8.5.9\webapps\Nexus\nexus-2.12.0-01\nexus" path="/nexus" reloadable="true"/>
</Host>
啟動Tomcat,在瀏覽器打開地址http://localhost/nexus,我用的是80端口,成功了。

5.修改本地的Maven配置文件內容
找到用戶的.m2/setting.xml文件,也可以在Eclipse的Preferences->Maven->User Settings->User Settings內找到。

打開此文件,在此文件內添加本地的Maven倉庫目錄,如:
<localRepository>F:\Maven\MavenRepository</localRepository>
添加Maven鏡像倉庫位置:
<mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost/nexus/content/groups/public/</url> </mirror> <mirror> <id>snapshots</id> <mirrorOf>snapshots</mirrorOf> <url>http://localhost/nexus/content/repositories/snapshots/</url> </mirror>
配置Profile及激活Profile
<profile>
<id>development</id>
<repositories>
<repository>
<id>central</id>
<url>http://localhost/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://localhost/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>development</activeProfile>
</activeProfiles>
添加認證信息,填寫正確的用戶名密碼
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
6.構建項目並部署到Nexus倉庫,修改pom文件(自動部署),這里到底是部署到release倉庫還是snapshots,具體還要看項目的version的后綴是snapshots還是release。
<!-- 自動部署構件到Nexus倉庫 --> <distributionManagement> <repository> <id>nexus-releases</id> <url>http://localhost/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <url>http://localhost/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
執行命令:mvn clean deploy 部署到Nexus倉庫內。
最終部署到Nexus倉庫效果如下,項目的version為0.0.1-RELEASE

