Maven 仓库的分类:(maven的仓库只有两大类)

1.本地仓库

2.远程仓库,在远程仓库中又分成了3种:

2.1 中央仓库

2.2 私服

2.3 其它公共库

有个maven私服可以很方便地管理我们的jar包和发布构建到远程仓库,本文就介绍了如何在linux下一步步使用nexus搭建maven私服。

私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。

 

首先安装好jdk 、maven

我这里安装的JDK 、maven版本信息如下:

  1. [root@localhost bin]# java -version
  2. java version "1.7.0_79"
  3. Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
  4. Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
  5. [root@localhost bin]# mvn -v
  6. Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)
  7. Maven home: /home/data/maven
  8. Java version: 1.7.0_79, vendor: Oracle Corporation
  9. Java home: /home/xuan/soft/jdk1.7.0_79/jre
  10. Default locale: en_US, platform encoding: UTF-8
  11. OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"

这里附上,环境配置:

  1. #java
  2. export JAVA_HOME=/home/data/java
  3. export PATH=$JAVA_HOME/bin:$PATH
  4. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  5. #maven
  6. export MAVEN_HOME=/home/data/maven
  7. export MAVEN_HOME
  8. export PATH=${PATH}:${MAVEN_HOME}/bin
  9. #nexus
  10. export RUN_AS_USER=root

下载安装

nexus下载地址:http://www.sonatype.org/nexus/go

解压后会在同级目录中,出现两个文件夹:nexus-oss-webapp-1.8.0和sonatype-work,前者包含了nexus的运行环境和应用程序,后者包含了你自己的配置和数据。

nexus-2.12.0-01-bundle.tar.gz

  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus
  2. [root@localhost soft]# tar -zxvf nexus-2.12.1-01-bundle.tar.gz
  3. nexus-2.12.1-01/
  4. nexus-2.12.1-01/nexus/

为了方便更新和切换版本,创建链接,更新或者切换版本只需更新链接即可:

  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus
  2. [root@localhost nexus]# pwd
  3. /home/xuan/soft/nexus
  4. [root@localhost nexus]# ls
  5. nexus-2.12.1-01  sonatype-work
  6. [root@localhost nexus]#
  7. ln -s /home/xuan/soft/nexus /home/data/nexus

启动nexus

  1. [root@localhost bin]# pwd
  2. /home/data/nexus/nexus-2.12.1-01/bin
  3. [root@localhost bin]# ./nexus
  4. Usage: ./nexus { console | start | stop | restart | status | dump }
  1. $ ./nexus start
  2. Starting Nexus OSS...
  3. Started Nexus OSS.

启动成功:

查看控制台:

  1. [root@localhost bin]# ./nexus console
  2. ****************************************
  3. WARNING - NOT RECOMMENDED TO RUN AS ROOT
  4. ****************************************
  5. Running Nexus OSS...
  6. Nexus OSS is already running.

查看nexus日志:

  1. [root@localhost logs]# pwd
  2. /home/data/nexus/nexus-2.12.1-01/logs
  3. [root@localhost logs]# tail -f ./wrapper.log
  4. jvm 1    | 2016-05-20 06:50:10,655-0700 INFO  [qtp1294005448-58] anonymous org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {s}->https://sonatype-download.global.ssl.fastly.net:443: Connection reset

配置nexus

访问网址:http://yourhostname:8081/nexus

访问网址:http://192.168.140.128:8081/nexus

右上角以admin登陆,默认用户名/密码:admin/admin123。

安装过程中可能遇到的错误:

1、进入启动目录,启动时不成功  提示

****************************************
WARNING – NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.

大概意思就是要在环境配置export RUN_AS_USER=root,临时配置

也可以在vi /etc/profile 文件末尾里添加export RUN_AS_USER=root  永久配置

2、访问不了虚拟机的,需要关闭防火墙
centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。

所以你只要停止firewalld服务即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

如果你要改用iptables的话,需要安装iptables服务:
sudo yum install iptables-services
sudo systemctl enable iptables && sudo systemctl enable ip6tables
sudo systemctl start iptables && sudo systemctl start ip6tables

下一步进行Maven 与私服的测试:

~/.m2/settings.xml

在maven的setting.xml文件增加使用nexus私服配置:

maven 私服地址 http://192.168.1.102:8081/nexus/content/groups/public/

maven 中央仓库地址:http://repo1.maven.org/maven2  (没有私服镜像可以中央仓库的)

  1. <settings>
  2. <mirrors>
  3. <mirror>
  4. <!--This sends everything else to /public -->
  5. <id>nexus</id>
  6. <mirrorOf>*</mirrorOf>
  7. <url>http://192.168.1.102:8081/nexus/content/groups/public/</url>
  8. </mirror>
  9. </mirrors>
  10. <profiles>
  11. <profile>
  12. <id>nexus</id>
  13. <!--Enable snapshots for the built in central repo to direct -->
  14. <!--all requests to nexus via the mirror -->
  15. <repositories>
  16. <repository>
  17. <id>central</id>
  18. <url>http://central</url>
  19. <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
  20. <snapshots><enabled>true</enabled></snapshots>
  21. </repository>
  22. <repository>
  23. <id>spring-release</id>
  24. <name>Spring Maven Release Repository</name>
  25. <url>http://repo.springsource.org/libs-release</url>
  26. <snapshots>
  27. <enabled>false</enabled>
  28. </snapshots>
  29. </repository>
  30. </repositories>
  31. <pluginRepositories>
  32. <pluginRepository>
  33. <id>central</id>
  34. <url>http://central</url>
  35. <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
  36. <snapshots><enabled>true</enabled></snapshots>
  37. </pluginRepository>
  38. </pluginRepositories>
  39. </profile>
  40. </profiles>
  41. <activeProfiles>
  42. <!--make the profile active all the time -->
  43. <activeProfile>nexus</activeProfile>
  44. </activeProfiles>
  45. <!-- deploy artifacts to repository. -->
  46. <servers>
  47. <server>
  48. <id>releases</id>
  49. <username>admin</username>
  50. <password>admin123</password>
  51. </server>
  52. <server>
  53. <id>snapshots</id>
  54. <username>admin</username>
  55. <password>admin123</password>
  56. </server>
  57. </servers>
  58. </settings>

测试效果图:

1、在项目的pom.xml文件  加入maven依赖测试

2、私服上的依赖

3、项目本地的依赖

参考文档:

http://tianweili.github.io/blog/2015/03/17/linux-nexus-maven-private-server/

maven 使用私服的参考文档:

http://blog.csdn.net/liujiahan629629/article/details/39272321

本地上传依赖到nexus服务器的两种方式:

1、通过网页上传
2、通过maven的方式depoly

在项目的pom.xml 加入如下配置 (这里不做详细介绍,可以参考上面的资料)

  1. <distributionManagement>
  2. <repository>
  3. <id>releases</id>
  4. <name>Nexus Release Repository</name>
  5. <url>http://192.168.1.102:8081/nexus/content/repositories/releases/</url>
  6. </repository>
  7. <snapshotRepository>
  8. <id>snapshots</id>
  9. <name>Nexus Snapshot Repository</name>
  10. <url>http://192.168.1.102:8081/nexus/content/repositories/snapshots/</url>
  11. </snapshotRepository>
  12. </distributionManagement>

运行命令:mvn package deploy 它会根据项目的pom.xml文件的配置如下  在私服生成些war包 (暂不知道在那些场景应用)

<groupId>com.xuan</groupId>

<artifactId>spring</artifactId>

<packaging>war</packaging>

<version>0.0.1-SNAPSHOT</version>

<name>springmvc_hibernate</name>

在私服生成

/com/xuan/spring/xxxxx.pom

/com/xuan/springxxxxx.war

nexus在linux上搭建的更多相关文章

  1. linux上搭建ftp

    linux上搭建ftp 重要 解决如何搭建ftp         解决用户指定访问其根目录         解决访问ftp超时连接         解决ftp主动连接.被动连接的问题 1.安装ftp ...

  2. 使用Nginx在windows和linux上搭建集群

    Nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器 特点:反向代理 负载均衡 动静分离… 反向代理(Reverse Pro ...

  3. linux上搭建ftp、vsftp, 解决访问ftp超时连接, 解决用户指定访问其根目录,解决ftp主动连接、被动连接的问题

    linux上搭建ftp 重要 解决如何搭建ftp         解决用户指定访问其根目录         解决访问ftp超时连接         解决ftp主动连接.被动连接的问题 1.安装ftp ...

  4. CentOS Linux上搭建PPPoE服务器及拨号设置

    CentOS Linux上搭建PPPoE服务器及拨号设置 搭建PPPoE,成功了的话,就觉得超级简单,在CentOS Linux更是5步左右就能搞定. 1.安装pppoe,安装完成后,会有pppoe- ...

  5. 【转帖】Linux上搭建Samba,实现windows与Linux文件数据同步

    Linux上搭建Samba,实现windows与Linux文件数据同步 2018年06月09日 :: m_nanle_xiaobudiu 阅读数 15812更多 分类专栏: Linux Samba 版 ...

  6. Linux上搭建SVN服务

    环境:centos7 一.搭建svn服务 1. 安装svn yum -y install subversion 2. 创建一个目录作为svn服务的地址(svn://192.168.0.2:3690 访 ...

  7. mongo学习笔记(六):linux上搭建

    linux分以下几台 monogos mongocfg mongod1 mongod2 1.用ssh把 mongodb-linux-x86_64-3.0.6.tgz 移到linux /root上 2. ...

  8. linux上搭建nginx+php+mysql环境详细讲解

    1.mysql安装 #安装编译环境 yum install -y gcc gcc-c++ gcc-devel g++ g++-devel; yum install -y wget yum instal ...

  9. Openfire+spark在linux上搭建内部聊天系统

    一.    实验环境 Ubuntu server14.04 openfire:http://www.igniterealtime.org/downloads/index.jsp spark:http: ...

随机推荐

  1. python正则表达式03--字符串中匹配数字

    import re # \d+ 匹配字符串中的数字部分,返回列表 ss = 'adafasw12314egrdf5236qew' num = re.findall('\d+',ss) print(nu ...

  2. Backbone.js Basics: Bringing an App to Life with Events

    http://www.sitepoint.com/backbone-basics-events/

  3. VS.NET2013发布网站的时候去掉.cs文件(预编译)(转)

      在要发布的网站上右键,选择"发布网站".   在发布窗口中,会让你选择一个发布配置文件,没有的话点击下拉菜单在里面选择新建一个. NEXT.   好,现在发布一下网站.发布出来 ...

  4. 优步UBER司机奖励政策:含高峰、翻倍、行程、金牌司机、保底奖励(持续更新...)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://didi-uber.com/archiv ...

  5. 【linux报错】-bash: xhost: command not found

    参考自:http://blog.csdn.net/csdnones/article/details/51513163,感谢原作者解决了我的问题. 执行xhost +,报以下错误,原因是因未没有安装相关 ...

  6. Android Studio 3.1.2 Device File Explorer nothing to show

    Android Studio 3.1.2 Device File Explorer nothing to  show 不显示 目录  ,空白 手持终端设备: Android  4.2.2  ,API1 ...

  7. Sqlite数据多表联合update

    其实在Mysql中,多表联合update不是什么难事. 语法: 1 UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ... ...

  8. SQL Server临时表漫谈

    SQL Server是微软的关系型数据库,对于刚入门的我是一个非常友好的开发工具.可视化界面的安装与操作,非常适合刚入门的我. 其实大家要找这方面的资料,在网上一搜一大堆,这里我就不赘述那些了,基本都 ...

  9. hadoop常见错误解决方法

    一.启动集群时 1.节点启动失败 1.1端口占用 1.1报错信息:address already in use - bind Address:50070 解决步骤: 查询端口占用:lsof -i:50 ...

  10. hive的简单使用

    一.一些说明 1.支持的操作 hive 默认不支持updata 和 delete操作 insert也是执行缓慢,主要用于数据的计算 hive 数据类型---字符串,大部分与java一致. 2.内外表的 ...