Maven零散笔记——配置Nexus




相关链接:
Maven零散笔记——常用配置
Maven零散笔记——配置Nexus


Nexus用于建立本地MVN仓库,我就不在这里罗嗦了。
当前的版本为2.0.6,可以直接 下载tar包,解压后进行简单配置就可以使用了!

安装&配置Nexus
闲言少叙,命令走起~
#下载
wget http://www.sonatype.org/downloads/nexus-2.0.6-bundle.tar.gz

#解压
tar zxvf nexus-2.0.6-bundle.tar.gz

#做软链接,方便操作,应个人需要
ln -s nexus-2.0.6 nexus

解压后,应该获得如下目录结构:
  • nexus-2.0.6是nexus服务主目录
  • sonatype-work是真正的仓库,同时包含了nexus的配置,如定时任务、用户配置等

12112346_6S1d.png

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


端口配置在 nexus/conf/nexus.properties文件中,文件如下:
# Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.

# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF
pr.encryptor.publicKeyPath=/apr/public-key.txt

如果你需要修改nexus服务端口或IP,上面这段修改就是了。

启动后,如下界面:
12112346_5WyG.png
默认管理员帐号:
用户名:admin
密码:admin123

注:最好现在就修改管理员密码!,nexus已经做得很人性化了,我就介绍如何修改密码了!

通常可以在maven工具里找到的包,也可以在这里找到:
12112347_pDbC.png

定制任务
当然,为了让你的nexus更加智能,需要做一些定时任务,譬如定期下载索引,加快本地mvn检索速度。
以建立定期下载索引为例,在 Administration选项中找到 Scheduled Tasks,在窗口页面点击 Add,进行配置:
12112347_HtPH.png

除此之外,我还经常要添加一些额外的jar到nexus中,譬如我要追加BC的组件包到nexus中,供团队其他开发成员使用。
找到 View/Repositories,打开 Repositories窗口,选择 3rd party,进行如下配置:
12112347_qXNh.png
之后,就可以在这里找到该jar了:
12112347_Bv5j.png

私服配置
为了让你的maven默认访问你的私服,需要配置settings.xml:
<mirrors>
...
		<mirror>
			<id>nexus</id>
			<mirrorOf>*</mirrorOf>
			<name>Nexus Mirror</name>
			<url>http://<Your Nexus IP>/nexus/content/groups/public</url>
		</mirror>
...
	</mirrors>
...
	<profiles>
		<profile>
			<id>nexus</id>
			<repositories>
				<repository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url><Your Nexus IP>/nexus/content/groups/public</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</repository>
				<repository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>

			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://<Your Nexus IP>/nexus/content/groups/public</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
				<pluginRepository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
...
	<activeProfiles>
		<activeProfile>nexus</activeProfile>
	</activeProfiles>


将jar部署至Nexus

如果通过Eclipse Maven工具,或者直接操作Maven命令行,将jar部署至nexus:
pom.xml
<project>  
...  
<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
      <name>Nexus Release Repository</name>  
      <url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url>  
  </snapshotRepository>  
</distributionManagement>  
...  
</project>


settings.xml
<settings>  
...  
<servers>  
  <server>  
    <id>nexus-releases</id>  
    <username>admin</username>  
    <password>admin123</password>  
  </server>  
  <server>  
    <id>nexus-snapshots</id>  
    <username>admin</username>  
    <password>admin123</password>  
  </server>    
</servers>  
...  
</settings>

最后,在项目目录中执行 mvn deploy

如果想要在发布jar的同时,把source一通发布,需要做这个配置:
<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>


应该够用了!

相关链接:
Maven零散笔记——常用配置
Maven零散笔记——配置Nexus

转载于:https://my.oschina.net/mohaiyong/blog/221315

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值