标签:
因为在 java开发中,经常用到第三方的 jar 包依赖,而这些依赖很乱,很杂,构建过程中经常产生意想不到的冲突,比如 jar 包冲突,版本不对等。如果能够用软件的方式,一条命令,快速的搭建 ssh(struct,spring,hibernate),ssi(struct, spring, ibatis) 开发环境,那会节省我们很多的时间去专注研发上 。
私服其实就是一种maven服务器,仅仅服务于某个公司,政府。把它架设在局域网的内部有很多好处,下载依赖变得快了,构建也快了,提高了工作效率。不需要担心找不到 jar 的问题,因为你可以配置maven 仓库。如果你需要下载一个jar包,突然发现私服没有,这时候私服会去外部的仓库下载,下载完后再发给你。以后就不需要再去网络上下载这个 jar 包了。一句话就是“一次投资,终生受益”。
另外,你还可以把你写的 jar 包发布到 maven 库里,供大家使用,仅仅只需要一条命令。
网络拓扑如下(截书里的)

需要准备一台服务器,linux 或者windows 都可以
下载地址:http://www.sonatype.org/nexus/downloads/
解压缩
启动 maven 服务器
进入解压目录
cd nexus-2.11.1-01-bundle/nexus-2.11.1-01/bin
然后执行
./nexus console
看到启动信息 jetty start 即启动成功,默认监听端口为:8081
http:// maven 服务器的ip:8081/nexus/#welcome
打开上面的链接,访问成功即可完成运行。

是不是很简单?
右上角的login in 默认密码是admin admin123 登陆后可修改私服的配置信息
    需要配置本地 Maven Home目录的 conf 目录里的 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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  
  <localRepository>E:/lib</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
  	 <server>  
            <id>releases</id>  
            <username>admin</username>  
            <password>admin123</password>  
        </server>  
        <server>  
            <id>snapshots</id>  
            <username>admin</username>  
            <password>admin123</password>  
        </server>  
        <server>  
            <id>deploymentRepo</id>  
            <username>admin</username>  
            <password>admin123</password>  
        </server>  
 
  </servers>
  <mirrors>
  </mirrors>
  
  <profiles>
	<profile>
		<id>nexus</id>
			<repositories>
				<repository>  
		        <id>releases</id>  
		        <name>mapbar thirdparty central mirror.</name>  
		        <url>http://192.168.200.5:8081/nexus/content/repositories/springio/</url>  
	   		 </repository>
			<repository>
				<id>nexus</id>
				<name>Nexus</name>
				<url>http://192.168.200.5:8081/nexus/content/groups/public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>nexus</id>
				<name>Nexus</name>
				<url>http://192.168.200.5:8081/nexus/content/groups/public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
  </profiles>
  <activeProfiles>
	<activeProfile>nexus</activeProfile>
</activeProfiles>
 
</settings>
里面的ip 填写你maven 服务器的ip 即可,就可以执行maven install , 然后你就会发现e:\lib 里面已经有了jar包,当然maven 服务器也有了,下次编译就不会去网络上找jar 包了。
标签:
原文地址:http://my.oschina.net/0x4ad/blog/490279