搭建Maven私服

用Nexus来搭建本地的Maven服务器

下载地址是:http://nexus.sonatype.org/downloads/

我下载的是:nexus-oss-webapp-1.8.0.1-bundle.tar.gz

 

一、安装服务器

 

解压下载的文件:

 

# tar xzvf nexus-oss-webapp-1.8.0.1-bundle.tar.gz

 

解压后目录:

 

nexus-oss-webapp-1.8.0.1 包含了nexus的运行环境和应用程序

 

sonatype-work 包含了你自己的配置和数据

 

启动nexus

 

进入nexus-oss-webapp-1.8.1目录

 

# cd nexus-oss-webapp-1.8.0.1/bin/jsw

 

根据自己机器选择版本

 

 

我选择的是 linux-x86-32

 

# cd linux-x86-32/

 

linux-x86-32目录结构:lib  nexus  nexus.pid  platform.conf  wrapper

 

nexus就是启动命令

 

# ./nexus

 

执行上面的命令,可以得到nexus命令的用法提示:start 命令启动,stop命令停止。下面启动nexus:

 

# ./nexus start

 

 

以上表示启动成功!

 

通过log文件查看更详细的信息

 

# cd ~/nexus-oss-webapp-1.8.0.1/log

 

# tail -f wrapper.log

 

在log中可以看到nexus默认监听的端口是8081。那么我们就可以在浏览器中访问:http://host:8081/nexus

 

默认用户名是admin密码是admin123

 

 

二、配置Nexus

 

由于在新搭建的nexus环境中只是一个空的仓库,所以第一步就是要和远程的Maven中心仓库进行同步。

 

 

 

 

如果在Reindex之后,并没有同步到远程的仓库,可以检查每个仓库的设置。下面是Maven Central的设置:

 

 

 

 三、在项目中使用私服

 

在完成了上面的配置后,就可以将项目中默认的Repository切换为本地的私服了,只需要在pom.xml中增加repositories就可以了:

 

Java代码   收藏代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.   <modelVersion>4.0.0</modelVersion>  
  4.   
  5.   <groupId>com.mycom.test</groupId>  
  6.   <artifactId>simple</artifactId>  
  7.   <version>0.0.1-SNAPSHOT</version>  
  8.   <packaging>jar</packaging>  
  9.   
  10.   <name>simple</name>  
  11.   <url>http://maven.apache.org</url>  
  12.   
  13.   <repositories>    
  14.     <repository>    
  15.       <snapshots>    
  16.         <enabled>true</enabled>    
  17.       </snapshots>    
  18.       <id>public</id>    
  19.       <name>Public Repositories</name>    
  20.       <url>http://192.168.1.7:8081/nexus/content/groups/public/</url>    
  21.     </repository>    
  22.   </repositories>  
  23.   <pluginRepositories>    
  24.     <pluginRepository>    
  25.       <id>public</id>    
  26.       <name>Public Repositories</name>    
  27.       <url>http://192.168.1.7:8081/nexus/content/groups/public//</url>    
  28.     </pluginRepository>    
  29.   </pluginRepositories>    
  30.   <properties>  
  31.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  32.   </properties>  
  33.   
  34.   <dependencies>  
  35.     <dependency>  
  36.       <groupId>junit</groupId>  
  37.       <artifactId>junit</artifactId>  
  38.       <version>3.8.1</version>  
  39.       <scope>test</scope>  
  40.     </dependency>  
  41.   </dependencies>  
  42. </project>  
 

将pom.xml保存后,再回过头来了看去nexus管理界面看,就会发现junit已经被下载到本地的nexus服务器中了。



添加缺少的jar包


Missing artifact org.freemarker:freemarker:jar:2.3.19:compile: 这就说明你的私人仓库中并没有freemarker.jar的包

现在就来给nexus库中加入我们需要的jar包

1.首先要下好相应的包:这是我放在的目录:

2.现在就是把它放进去了:

打开cmd 输入:

mvn install:install-file -DgroupId=org.freemarker  -DartifactId=freemarker -Dversion=2.3.19 -Dfile=E:\文件\java\freemarker\freemarker-2.3.19\lib\freemarker.jar -Dpackaging=jar -DgeneratePom=true

回车就行了;

现在再刷新下你的工程就行了!



1、maven包查询:

   http://mvnrepository.com/
2、maven公共仓库

   http://mirrors.ibiblio.org/pub/mirrors/maven2/
   http://gradle.artifactoryonline.com/gradle/libs

   http://gradle.artifactoryonline.com/gradle/plugins
   http://google-maven-repository.googlecode.com/svn/repository
   http://maven.springframework.org/release
   http://maven.springframework.org/milestone
   http://repository.codehaus.org
   http://repository.jboss.org/nexus/content/groups/public-jboss
   http://repo.jfrog.org/artifactory/plugins-releases-local
   http://repo.jfrog.org/artifactory/libs-releases-local
   http://download.java.net/maven/1
   http://download.java.net/maven/2
   http://repo1.maven.org/maven2
   http://www.intalio.org/public/maven2/

   http://www.jarvana.com/jarvana/browse/

   http://maven.alfresco.com/nexus/content/groups/public



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值