如何搭建maven 引用 war pom私服,用.war

Ubuntu 14 使用Nexus2.x为Maven3.x搭建私服构件仓库 – 默默的点滴
2017年十月
1718202122
23242526272829
一、下载与安装Nexus
想为Maven搭建私服,我们可以选择使用Nexus工具,目前已知提供war包的版本为2.2.0,其下载地址为:
这里我们下载War包,直接部署到Tomcat 7 下面,Ubuntu 下面是 /var/lib/tomcat7/webapps。
接下来我们可以在浏览器中输入查看Nexus是否成功.
如果提示错误,则到 /var/log/tomcat7/localhost.YYYY-MM-DD.log 下面查看日志,有可能报告 /usr/share/tomcat7/sonatype-work 权限问题,则说明Nexus 没有权限创建这个目录,因此我们需要手工创建这个目录,然后赋予这个目录 777权限,然后重启 Tomcat.
目前最新的版本,貌似已经不提供war包下载了,因此只能是使用jetty的版本了。
Ubuntu下面的操作如下:
$wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.12.0-01-bundle.tar.gz
$sudo mkdir /var/opt/nexus-2.12.0-01
$sudo tar -zxvf nexus-latest-bundle.tar.gz -C /var/opt/nexus-2.12.0-01
$sudo ln -s /var/opt/nexus-2.12.0-01/nexus-2.12.0-01/ /var/opt/nexus
$cd ~&$wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.12.0-01-bundle.tar.gz&$sudo mkdir /var/opt/nexus-2.12.0-01&$sudo tar -zxvf nexus-latest-bundle.tar.gz -C /var/opt/nexus-2.12.0-01&$sudo ln -s /var/opt/nexus-2.12.0-01/nexus-2.12.0-01/ /var/opt/nexus
bin/jsw/conf/wrapper.conf,设置
wrapper.java.command=jdk所在目录/bin/java。
$whereis java
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
$sudo vim /var/opt/nexus/bin/jsw/conf/wrapper.conf
$whereis javajava: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz&$sudo vim /var/opt/nexus/bin/jsw/conf/wrapper.conf
修改后的内容如下:
..........
mand=/usr/bin/java
..........
..........wrapper.java.command=/usr/bin/java..........
设置目录的权限
$chmod -R 777 /var/opt/nexus-2.12.0-01/sonatype-work
$chmod -R 777 /var/opt/nexus/logs
$chmod -R 777 /var/opt/nexus/tmp
$chmod -R 777 /var/opt/nexus/bin/jsw/linux-x86-64
$chmod -R 777 /var/opt/nexus/bin/jsw/linux-x86-32
$chmod -R 777 /var/opt/nexus-2.12.0-01/sonatype-work&$chmod -R 777 /var/opt/nexus/logs&$chmod -R 777 /var/opt/nexus/tmp&$chmod -R 777 /var/opt/nexus/bin/jsw/linux-x86-64&$chmod -R 777 /var/opt/nexus/bin/jsw/linux-x86-32
$/var/opt/nexus/bin/nexus start
Starting Nexus OSS...
Started Nexus OSS.
$/var/opt/nexus/bin/nexus start&Starting Nexus OSS...Started Nexus OSS.
这种安装模式下,访问的链接地址为
注意,首次启动的耗时时间很长,貌似需要建立数据库等,需要耐心等待几分钟。
如果成功,则出现下面的界面
通过上图我们可以发现我们已经成功的启动了Nexus,那么接下来要做的事情就更有意思了,在后续章节中笔者会陆续讲到应该如何使用Nexus工具来配置和管理咱们的私服仓库。
二、仓库类型
在上一章节中,笔者讲解了如何下载与安装Nexus工具。那么本章节咱么来看看如何使用Nexus工具配置和管理私服仓库。当然在使用Nexus之前你是需要登录的,缺省账号密码为:
account:admin;
password:admin123;
当成功登录后,你可以单击 Repositories属性看到如下页面:
由于admin这个账号是属于Administrator权限的,你也可以通过单击Security属性进行账户的配置:
Nexus的仓库类型一共有4种,每一种仓库类型均对应有不同的操作方式:
1、group: 仓库组;
2、hosted:宿主;
3、proxy:代理;
4、virtual:虚拟;
来吧,咱们先谈谈仓库组这个概念,一个仓库组类似一个仓库集合,它和仓库之间是一对多的关系,也就是说一个仓库组可以允许包含多个仓库,Nexus仓库用例图如下:
在咱们弄明白仓库组的作用后,咱们接着来看宿主仓库是干什么的。其实所谓宿主仓库可以理解为自定义仓库,用于存放一些在中央仓库无法下载的构件,比如自定义构件(你可以手动将自定义构件上传至hosted中)。
代理仓库起到的作用是代理作用,假设本地仓库向私服进行请求时,首先会去私服仓库的本地路径中寻找构件,如果没有找到则会从中央仓库进行下载。
虚拟仓库省略...
三、使用Nexus管理私服仓库
在了解Nexus的4种仓库类型后,咱们接下来要做的事情就是使用Nexus工具来管理咱们的私服仓库。先来看看Nexus为我们提供的一些缺省仓库:
从上图我们可以看出Nexus缺省为我们定义了1个仓库组,7个仓库。当中最主要的几个仓库为:
3rd party(宿主仓库):用于存放一些在中央仓库无法下载的构件仓库;
Apache Snapshots(代理仓库):代理ApacheMaven仓库快照版本的构件仓库;
Central(代理仓库):代理Maven中央仓库中发布版本构件的仓库;
当然你可以根据项目需要新建仓库组及仓库,但在建立这些私有的仓库之前,咱们还是先来看看如何使用Nexus为咱们提供的缺省构件仓库(其实很多时候你真没必要去新建仓库)。
选择Public Repositories分组,单击configuration选项,你可以为仓库组添加对应的仓库:
单击Save按钮保存即可配置完成。这里有一点需要提醒大家的是,仓库的添加顺序直接决定了构件的下载顺序,换句话来说我们应该把需要从中央仓库或者其他远程仓库下载构件的代理仓库添加在最后。
当咱们成功将指定的仓库集合添加进仓库组后,接下来我们来为3rd party(宿主仓库)上传自定义构件,所谓自定义构件指的是无法从Maven的中央仓库进行下载的构建。
笔者在此选用的是最简单方便的手动上传构件(当然上传构件至宿主仓库还有一些方式,但笔者还是侧重于最简便的方式)。
单击3rd party(宿主仓库)的Artifact Upload选项,我们首先来上传一个基于Maven项目的自定义构件:
最后别忘记了添加构件:
如果你的构件不是基于Maven的呢?那么你可以选择GAV Parameters属性:
接下来,需要配置 Maven 来连接到似有仓库,如果需要全局配置,则配置地址为 ~\.m2\setting.xml,如果需要根据工程配置,则需要跟pom.xml在同一个目录下面即可,文件存在则修改,不存在则创建,内容如下
&profiles&
&id&dev&/id&
&repositories&
&repository&
&id&nexus&/id&
&url&http://127.0.0.1:8080/nexus/content/groups/public/&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus&/id&
&url&http://127.0.0.1:8080/nexus/content/groups/public&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/pluginRepository&
&/pluginRepositories&
&/profile&
&/profiles&
&activeProfiles&
&activeProfile&dev&/activeProfile&
&/activeProfiles&
123456789101112131415161718192021222324252627282930313233
&profiles& &profile&
&id&dev&/id&
&repositories&
&repository&
&id&nexus&/id&
&url&http://127.0.0.1:8080/nexus/content/groups/public/&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus&/id&
&url&http://127.0.0.1:8080/nexus/content/groups/public&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/pluginRepository&
&/pluginRepositories& &/profile&&/profiles&&&activeProfiles& &activeProfile&dev&/activeProfile&&/activeProfiles&nexus建立maven仓库私服及Snapshots、release的版本管理
时间: 19:20:03
&&&& 阅读:3009
&&&& 评论:
&&&& 收藏:0
标签:环境搭建
1、linux安装maven
tar zxvf&apache-maven-3.0.5-bin.tar.gz
mv&apache-maven-3.0.5 /usr/local/apache-maven-3.0.5
vi /etc/profile
export MAVEN_HOME=/usr/local/apache-maven-3.0.5
export PATH=$PATH:$MAVEN_HOME/bin
source /etc/profile&
2、linux安装nexus
需要的安装包:nexus-2.11.4-01-bundle.tar(csdn下载地址:http://download.csdn.net/detail/carboncomputer/9595216)
需要jdk版本1.7以上
tar zxvf&nexus-2.11.4-01-bundle.tar
端口配置文件,可修改端口:/nexus-2.11.4-01/conf/nexus.properties
cd nexus-2.11.4-01/bin
./nexus& start
本地机器访问:
如果启动成功,就会显示如下:
如果在启动过程中说要求root权限的。可以百度解决,或者用sudo sh&nexus& start启动。
用默认的账号密码登录:admin/admin123
环境就部署好了,现在是使用maven仓库。
注意:严重不提倡使用nexus3.0以上的版本,一开始用这个,安装时很多问题需要解决,此外,新的界面很难使用。官网上也是推荐使用maven时采用nexus2.X版本。
maven仓库使用及版本发布管理
点击仓库列表
主要是两个类型:
snapshots:开发过程中的版本仓库
release:正式发布的版本仓库
public是maven主库
nexus默认新建了一个库:3rd party,专门存放第三方的jar,这个所搜搜几篇文章看看就有说明了。这里对于这个不一一说了,主要是介绍如何使用nexus来管理版本和本地开发过程。
上传第三方的jar如下:
snapshots、release全部开发允许部署的权限,如下
本地是windows下的myeclipse10进行开发的,myeclipse10自带maven插件,直接使用,不需要加载这个插件,其他的比如eclipse需要自行处理。
myeclipse配置setting.xml
现在来看看setting.xml文件
&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&D:/maven/maven_jars&/localRepository&
& &pluginGroups&
& &/pluginGroups&
& &proxies&
& &/proxies&
& &servers&
&&& &id&releases&/id&
&&&&&&& &username&deployment&/username&
&&& &password&admin123&/password&
&&&& &id&snapshots&/id&
&&&& && &username&deployment&/username&
&&&& &password&admin123&/password&&&&&
&/server&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&& &id&public&/id&
&&&&&&& &username&deployment&/username&
&&&&&&& &password&admin123&/password&
&/servers&
& &mirrors&
&&&& &mirror&
&&&&& &id&nexus&/id&
&&&&& &mirrorOf&nexus&/mirrorOf&
&&&&& &name&nexus Repositories&/name&
&&&&& &url&http://120.76.206.82:8081/nexus/content/repositories/thirdparty/&/url&
&&& &/mirror&
& &/mirrors&
& &profiles&
& &activeProfiles&&&
&&&&&&& &activeProfile&dev&/activeProfile&&&
&&& &/activeProfiles&&
&/settings&
建立maven工程
pom.xml的内容设置如下:
&&project&xmlns=&"http://maven.apache.org/POM/4.0.0"&xmlns:xsi=&"http://www.w3.org/2001/XMLSchema-instance"
&&xsi:schemaLocation=&"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&
&&&&modelVersion&&4.0.0&&/modelVersion&&
&&&&groupId&&News_Recommend&/&groupId&
&&&&artifactId&&News_Recommend&/&artifactId&
&&&&version&&0.0.5-SNAPSHOT&/&version&
&&&&packaging&&jar&/&packaging&
&!-- 设定主仓库 --&
&&repositories&
&!--&nexus私服 --&
&&repository&
&&id&&public&/&id&
&&url&&http://xxxx:8081/nexus/content/groups/public/&&/url&&
&&releases&
&&enabled&&true&/&enabled&
&/&releases&
&&snapshots&
&&enabled&&true&/&enabled&
&/&snapshots&
&/&repository&
&/&repositories&
&!-- 自动打包 --&
&&&&&distributionManagement&&
&&&&&&&&&repository&&
&&&&&&&&&&&&&id&&releases&&/id&&
&&&&&&&&&&&&&&url&&http://xxxx:8081/nexus/content/repositories/releases&&/url&&
&&&&&&&&&/repository&&
&&&&&&&&&snapshotRepository&&
&&&&&&&&&&&&&id&&snapshots&&/id&&
&&&&&&&&&&&&&&url&&http://xxxx:8081/nexus/content/repositories/snapshots&&/url&&
&&&&&&&&&/snapshotRepository&&
&&&&&/distributionManagement&&
&&dependencies&
&&dependency&
&&&&&&&groupId&&&junit&/&groupId&
&&&&&&&artifactId&&&junit&/&artifactId&
&&&&&&&version&&3.8.1&&/version&&
&&&&&&&scope&&test&&/scope&&
&&&&&/dependency&&
&&&&&dependency&&
&&&&&&&groupId&&com.oracle&&/groupId&&
&&&&&&&artifactId&&&ojdbc&/&artifactId&
&&&&&&&version&&10.1.0.2.0&&/version&&
&&&&&/dependency&&
&&&&&&dependency&&
&&&&&&&groupId&&&com&/&groupId&
&&&&&&&artifactId&&&testjar&/&artifactId&
&&&&&&&version&&1.0.0&&/version&&
&&&&&/dependency&&
&&&&&&dependency&&
&&&&&&&groupId&&News_Recommend&&/groupId&&
&&&&&&&artifactId&&News_Recommend&&/artifactId&&
&&&&&&&version&&0.0.1&&/version&&
&&&&&/dependency&&
&/&dependencies&
&&plugins&
&&groupId&&org.apache.maven.plugins&/&groupId&
&&artifactId&&maven-compiler-&plugin&/&artifactId&
&&configuration&
&&source&&${jdk.version}&/&source&
&&target&&${jdk.version}&/&target&
&/&configuration&
&/&plugin&
&&&&&&&&&&&&&groupId&&org.apache.maven.plugins&&/groupId&&
&&&&&&&&&&&&&artifactId&&&maven-war-plugin&&/artifactId&&
&&&&&&&&&&&&&version&&2.4&&/version&&
&&&&&&&&&&&&&configuration&&
&&&&&&&&&&&&&&&&&failOnMissingWebXml&&false&&/failOnMissingWebXml&&
&&&&&&&&&&&&&/configuration&&
&&&&&&&&&/plugin&&
&/&plugins&
&&finalName&&News_Recommend&/&finalName&
&/&project&
下面来生成开发版本的jar并自动上传到snaport仓库
工程右键--&run as--&run configuration
打开nexus后台可以看到打包成功并上传的jar:
接下来,如何生成release版本呢,只需要修改pom.xml
&&&groupId&&News_Recommend&/&groupId&
&&&&artifactId&&News_Recommend&/&artifactId&
&&&&version&&0.0.5-SNAPSHOT&/&version&
&&&&packaging&&jar&/&packaging&
&&&groupId&&News_Recommend&/&groupId&
&&&&artifactId&&News_Recommend&/&artifactId&
&&&&version&&0.0.5&/&version&
&&&&packaging&&jar&/&packaging&
打开nexus后台查看正式版本:
工程进行正式升级时只需要在pom.xml配置新增的jar依赖包即可,如下:
&原文地址:/zhongshengzhen/p/nexus_maven.html
弄了两天才有了眉目,希望对大家有用,不吝赐教和点赞,谢谢。
&&国之画&&&& &&&&chrome插件&&
版权所有 京ICP备号-2
迷上了代码!博客分类:
错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories. Could not resolve artifact Missing org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE 解决思路:在本地库中装载maven-archetype-quickstart
从{_}{+} 下载最新版maven-archetype-quickstart-1.1.jar
2.cmd窗口执行mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=d:\down\maven-archetype-quickstart-1.1.jar红字是你jar包放在的位置 Maven使用log4j可能会有协议上的问题
如果log4j的版本在1.2.14以上,则会出现下面的错误:
Missing artifact javax.jms:jms:jar:1.1:compileMissing artifact com.sun.jdmk:jmxtools:jar:1.2.1:compileMissing artifact com.sun.jmx:jmxri:jar:1.2.1:compile
原因是log4j在1.2.15及以上版本更换了协议,与jms冲突。解决办法有两种:一是使用1.2.14版本,二是手动下载jms.jar,安装到maven本地仓库中去。
maven工程pom添加log4j依赖:&dependency&&groupId&log4j&/groupId& &artifactId&log4j&/artifactId& &version&1.2.15&/version& &/dependency&出现错误:12-10-29 上午09时08分41秒: Missing artifact javax.jms:jms:jar:1.1:compile 12-10-29 上午09时08分41秒: Missing artifact com.sun.jdmk:jmxtools:jar:1.2.1:compile12-10-29 上午09时08分41秒: Missing artifact com.sun.jmx:jmxri:jar:1.2.1:compile 解决方案。改为如下:&dependency&&groupId&log4j&/groupId& &artifactId&log4j&/artifactId& &version&1.2.15&/version& &exclusions& &exclusion& &groupId&com.sun.jmx&/groupId& &artifactId&jmxri&/artifactId& &/exclusion& &exclusion& &groupId&com.sun.jdmk&/groupId& &artifactId&jmxtools&/artifactId& &/exclusion& &exclusion& &groupId&javax.jms&/groupId& &artifactId&jms&/artifactId& &/exclusion& &/exclusions& &/dependency& MyEclipse中的Web工程 转为 Maven支持的项目,步骤如下:(基于Windows XP 系统下 MyEclipse8.6版本) 【黄色背景部分可随意修改】
准备工作,下载安装 Maven 3.X 版本,然后将 安装目录下的 conf/settings.xml 文件拷贝到 ~/.m2/ (~表示用户目录,XP系统是C:\Documents and Settings\Administrator) 目录下,并修改其中的配置(不推荐直接修改安装目录下的settings.xml文件):
0.1 &settings& 标签下添加如下子标签,用以更改本地Maven库的路径(此项可选);
&localRepository&D:/maven/repository&/localRepository&
0.2 &proxies& 标签下添加如下子标签,配置http代理;
&proxy& &id&personal&/id& &active&true&/active& &protocol&http&/protocol& &host&172.17.18.80&/host& &port&8080&/port& &/proxy&
0.3 &mirrors& 标签下添加如下子标签,将本地所有的Maven请求从中央仓库转为私服中,提高下载效率和减少对中央仓库的依赖;
&!-- 本地请求全部转到私服中下载 --& &mirror& &id&nexus&/id& &mirrorOf&*&/mirrorOf& &name&All local request turn to nexus repository&/name& &url&{*}
{*}&/url& &/mirror&
0.4 &profiles&标签添加如下子标签,
&profile& &id&nexus&/id& &!-- 配置仓库请求 --& &repositories& &repository& &id&central&/id& &url&
&/url& &releases& &enabled&true&/enabled& &/releases& &snapshots& &enabled&true&/enabled& &/snapshots& &/repository& &/repositories& &!-- 配置插件仓库请求 --& &pluginRepositories& &pluginRepository& &id&central&/id& &url&
&/url& &releases& &enabled&true&/enabled& &/releases& &snapshots& &enabled&true&/enabled& &/snapshots& &/pluginRepository& &/pluginRepositories& &/profile&
0.5 &settings&标签下面添加如下子标签,
&activeProfiles& &activeProfile&nexus&/activeProfile& &/activeProfiles&
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
将以下代码拷贝到工程根路径下的 .project 文件中的 &buildSpec& 标签下(如果代码存在,则无需拷贝)
&buildCommand& &name&org.maven.ide.eclipse.maven2Builder&/name& &arguments&&/arguments& &/buildCommand&
将以下代码拷贝到工程根路径下的 .project 文件中的 &natures& 标签下(如果代码存在,则无需拷贝)
&nature&org.maven.ide.eclipse.maven2Nature&/nature&
将以下代码拷贝到工程根路径下的 .classpath 文件中的 &classpath& 标签下(如果代码存在,则无需拷贝)
&classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/&
重启MyEclipse,看到如下Maven依赖
让maven能够支持现有工程,无非就是让它知道两点:1。java文件存在哪?2。web根目录在哪?那么使用刚说的方法,在myeclipse里随便创建一个带有maven的WEB工程,将其中的pom.xml配置文件拷出来,放到现有工程的根目录下,然后简单地修改一下这个配置文件里的内容即可。下面列举几个关键的修改点:&build& &sourceDirectory&${basedir}/src&/sourceDirectory& &outputDirectory&${basedir}/web/WEB-INF/classes&/outputDirectory& ...... &plugins& &plugin&&artifactId&maven-war-plugin&/artifactId& &configuration& &webappDirectory&${basedir}/web&/webappDirectory&&warSourceDirectory&${basedir}/web&/warSourceDirectory& &/configuration& &/plugin& ...... &/plugins& &/build&明眼人一看就知道,将其中的&sourceDirectory&${basedir}/src&/sourceDirectory&改成自己java文件存放目录,将&webappDirectory&${basedir}/web&/webappDirectory&改成WEB根目录即可。
浏览 24602
可以参考最新的文档:,地址:地址:非常感谢
浏览: 413236 次
来自: 上海
请问service这个方法里为什么要while(true)啊? ...
springaop_springmvc 写道可以参考最新的文档 ...
可以参考最新的文档:如何在eclipse jee中检出项目并转 ...
很好,谢谢
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'用户名:兴趣e族
文章数:85
访问量:48200
注册日期:
阅读量:1297
阅读量:3317
阅读量:581205
阅读量:465820
51CTO推荐博文
  在本机上搭建私服1、去官网下载nexus  下载网址: &&&&&&下载格式:下载格式&(还有格式&)&:&nexus-2.7.0-06.war&(直接放入运行)2、将war复制到tomcat的wabapps中并运行tomcat(启动私服):  默认会创建 C:/用户/sonatype-work&目录  650) this.width=650;" src="/blog/508/69-.jpg" alt="" />  浏览器访问地址:&&&&&&&账户:admin,密码:admin123&&& 650) this.width=650;" src="/blog/508/31-.png" alt="" />  Nexus提供四种主机:  1、proxy&代理主机(私服连接中央仓库)  2、hosted 宿主(第三方jar包&收费,&不对外开放)  3、virtual 虚拟主机,用来兼容老版本的maven项目  4、group主机群,在下载jar遍历group中的每一个主机  650) this.width=650;" src="/blog/508/69-.png" alt="" />  public&主机群,包括四个主机遍历  Releases&发布版 (存放本公司内部自己编写的项目)  Snapshorts&测试版(存放本公司内部自己编写的项目)  3、修改代理中央仓库的属性  650) this.width=650;" src="/blog/508/28-.png" alt="" />  把false改为  1、覆盖原来的索引:  将central-ctx.zip&解压到 C:\Users\root\sonatype-work\nexus\indexer\central-ctx      sonatype-work\nexus\indexer:目录存放索引      sonatype-work\nexus\storage&目录存放包&(将下发本地仓库解压&)  2、将本地仓库覆盖nexus私服仓库  解压覆盖&C用户storage\central&  连接私服,下载jar包   本地要连接私服,在本地环境&配置连接私服镜像&&&&&&mirror&&&&&&& &id&nexus&/id&&&&&& &mirrorOf&*&/mirrorOf&&&&& &url&http://localhost/nexus-2.7.0-06/content/groups/public/&/url&&&&&&/mirror&  进行环境& 打开&  Window&-prefenrences&--&maven&---&update&settings&   650) this.width=650;" src="/blog/508/06-.png" alt="" />    maven仓库视图发生变化:  650) this.width=650;" src="/blog/508/69-.png" alt="" />   现在就可以从私服中下载jar包了,如果私服中没有的jar包,私服会连接到中央仓库中去下载。  连接私服,将开发好的项目,上传到私服  下载jar包,不需要身份认证,上传项目到私服,必须要进行身份的认证。  650) this.width=650;" src="/blog/508/12-.jpg" alt="" />  如果发布版本项目,版本号以结尾,如果测试版本&以结尾&    1、&需要在本机&环境&配置用户名和密码&  &server&&存放一组用户名和密码&  650) this.width=650;" src="/blog/508/22-.png" alt="" />  2、&配置项目添加连接私服地址&  &distributionManagement&&  650) this.width=650;" src="/blog/508/19-.png" alt="" />  3、使用maven的命令:deploy&测试发布结果  650) this.width=650;" src="/blog/508/09-.png" alt="" />  发布项目之前,私服必须要重启!&本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:未分类┆阅读(0)┆评论(0)首页 & 协同敏捷自动化, 开源软件nexus搭建maven私服 公司的maven私服跑了两年多了,最近朋友让帮忙给他搭建maven私服。这里做个总结吧。首先,先问个问题,有公共的maven仓库服务器,为什么还要搭建maven私服呢?在本地搭建后有如下几个优点:1、加速构建;2、节省带宽;3、节省中央maven仓库的带宽;4、稳定(应动一旦中央服务器出问题的情况);5、控制和审计;6、能够部署第三方构件;7、可以建立本地内部仓库;8、可以建立公共仓库。有这么多优点还不足以吸引你吗? 一、nexus下载安装 1、nexus的安装 官方下载归档页面为:http://www.sonatype.org/nexus/archived 在上面的页面上可以下载到目前的所有版本的nexus ,目前的最新版本为2.7.2 ,官方提供了tar、war、zip三种格式的下载。我这里下载的是zip包。#cd /App
#mkdir nexus
#wget /nexus/oss/nexus-2.7.2-bundle.zip
#unzip nexus-2.7.2-bundle.zip
#cd nexus-2.7.2/bin
#sh nexus start
注:nexus由于是java语言开发的,所以依赖java环境,要先确认主机上有java环境,如果是windows主机请启动nexus.bat或bin/jsw/windows-x86-32(或64)的相应目录下去启动或安装服务。 报错1:[root@localhost bin]# sh nexus start
****************************************
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.上面的错误原因很简单,因为使用了root用户。解决方法很简单,新建一个用户nexus也好,www也好,然后赋予权,重启。#useradd www
#chown www:www /App/nexus
#sh nexus start报错2:wrapper
| JVM exited while loading the application.
| Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
| Could not find the main class: org.sonatype.nexus.bootstrap.jsw.JswLauncher.
Program will exit.
| There were 5 failed launches in a row, each lasting less than 300 seconds.
Giving up.
There may be a configuration problem: please check the logs.
| &-- Wrapper Stopped 经在网上查到原因是,最新版本的maven需要依赖java1.7,该问题在公司的nexus升级时也遇到过。这里只是为了做演示,懒得在测试机上更换jdk了,直接下了nexus-2.5的版本。然后重新做上面的步骤。 报错3:ception: Address already in use
| java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method) ~[na:1.6.0_29] 因为默认的8081端口,已经被另外一个程序占有了,vim /App/nexus/nexus-2.5.0-04/conf/nexus.properties ,找到application-port=8081更改下端口,然后重新启动。通过http://IP:端口就可以访问了,登录以后,右上角有登录选项,默认用户名密码是admin/admin123 。 2、nginx反向代理nexusserver {
listen 80;
server_ //配置的域名
location / {
proxy_pass
http://127.0.0.1:8081; //跳转到的地址
proxy_set_header Host $
proxy_set_header X-Real-IP $remote_
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_
二、nexus配置 1、ldap认证 如下图所示,依次选择左侧的security--&LDAP Configuration,后按下面的配置进行配置:
操作方法security-&roles-&add-&External Role Mapping,Realm选择LDAP,Role里如果没有数据,说明ldap没设置好,Role里选择一个组,点击create mapping。 然后在configuration中选择add,添加两个权限,一个是Nexus deployment role,一个是All maven repositories (Full control)。 然后在对应组的小伙伴们就有权限了。 2、nexus仓库 nexus有四种仓库: group(仓库组):Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库; hosted(宿主):主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件; proxy(代理):代理公共的远程仓库; virtual(虚拟):用于适配 Maven 1 。 首次登录后会发现一个公共组仓库,其包含以下内容。 Public Repositories:& 仓库组 3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库 Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库 Central: 用来代理maven中央仓库中发布版本构件的仓库 Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库 Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库 Releases: 用来部署管理内部的发布版本构件的宿主类型仓库 Snapshots:用来部署管理内部的快照版本构件的宿主类型仓
3、配置远程索引 新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。点击左边Administration菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。
这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index ,如查看到有索引目录,表示已经OK 。 注:这个可以根据自己的实际需要去设置,以避免都开启的话一是会占用带宽(大量的下载远程文件),二是有可能会有爆仓的可能(这个在后面也会提到) 。 4、建立宿主仓库 新 建公司的内部仓库,步骤为Repositories –& Add –& Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入test 和 test repostiory,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了。
5、Nexus仓库组 Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。 neuxs默认自带了一个名为“Public Repositories”组,点击该组可以对他保护的仓库进行调整,把刚才建立的公司内部仓库test repostiory加入其中,这样就不需要再在maven中明确指定内部仓库 的地址了。同时创建一个Group ID为public-snapshots、Group Name为Public Snapshots Repositories的组,把Apache Snapshots、Codehaus Snapshots、Snapshots和zfyrepostiory加入其中。
三、maven客户端配置 maven客户端的settings.xml文件#vim /App/maven/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"&
&pluginGroups&&/pluginGroups&
&proxies&&/proxies&
&id&nexus-releases&/id&
&username&admin&/username&
&password&admin123&/password&
&id&nexus-snapshots&/id&
&username&admin&/username&
&password&admin123&/password&
&/servers&
&id&nexus-releases&/id&
&mirrorOf&*&/mirrorOf&
&url&/nexus/content/groups/public&/url&
&id&nexus-snapshots&/id&
&mirrorOf&*&/mirrorOf&
&url&/nexus/content/groups/public-snapshots&/url&
&/mirrors&
&profiles&
&id&nexus&/id&
&repositories&
&repository&
&id&nexus-releases&/id&
&url&http://nexus-releases&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/repository&
&repository&
&id&nexus-snapshots&/id&
&url&http://nexus-snapshots&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus-releases&/id&
&url&http://nexus-releases&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/pluginRepository&
&pluginRepository&
&id&nexus-snapshots&/id&
&url&http://nexus-snapshots&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/pluginRepository&
&/pluginRepositories&
&/profile&
&/profiles&
&activeProfiles&
&activeProfile&nexus&/activeProfile&
&/activeProfiles&
&/settings&
注:settings文件中在配置ldap认证时,由于默认保存的是明文密码,这样就导致不十分安全,可以通过mvn --encrypt-master-password 密码的方式生成加密过的密码文件。这个是需要mvn版本支持的,具体可以查看官方文档及配置说明。 maven项目下的pom.xml文件&distributionManagement&
&!-- 两个ID必须与 setting.xml中的&server&&id&nexus-releases&/id&&/server&保持一致--&
&repository&
&id&nexus-releases&/id&
&name&Nexus Release Repository&/name&
&url&/nexus/content/repositories/releases&/url&
&/repository&
&snapshotRepository&
&id&nexus-snapshots&/id&
&name&Nexus Snapshot Repository&/name&
&url&/nexus/content/repositories/snapshots&/url&
&/snapshotRepository&
&/distributionManagement&
四、注意事项 1、爆仓问题的解决方法 login-&scheduled tasks-&add,添加一个定时清理目录的计划任务即可。最后一个选项“remove if released”需要慎重,平时开发可能不是特别正规的时候可能会snapshot和release都需要。 2、减少后端压力 该方法也是从网上了解到的,可以通过前端nginx开启cache功能减少后端nexus maven仓库的压力。
本站的发展离不开您的资助,金额随意,欢迎来赏!
分类: 协同敏捷自动化, 开源软件 maven, nexus您可能也喜欢Maven deploy war到tomcat6、tomcat7 Maven +Tomcat+m2eclipse的deploy部署 maven打包之hello world maven安装配置及pom.xml与setting.xml优先级 nexus索引及其他 捐助本站
如您感觉本博客有用,可扫码向本博客捐赠近期文章 python实现hp刀片ilo地址配置 shell实现hp刀片ilo地址配置 根据IP和掩码计算网段 shell实现netmask掩码和cidr掩码位转换 s权限位引发postfix及crontab异常处理文章归档 文章归档 选择月份 2017年九月 &(5) 2017年八月 &(3) 2017年七月 &(4) 2017年六月 &(2) 2017年五月 &(3) 2017年三月 &(3) 2017年二月 &(2) 2017年一月 &(4) 2016年十二月 &(4) 2016年十一月 &(6) 2016年十月 &(5) 2016年九月 &(5) 2016年八月 &(9) 2016年七月 &(5) 2016年六月 &(10) 2016年五月 &(18) 2016年四月 &(5) 2016年三月 &(4) 2016年二月 &(5) 2016年一月 &(8) 2015年十二月 &(8) 2015年十一月 &(9) 2015年十月 &(17) 2015年九月 &(10) 2015年八月 &(25) 2015年七月 &(11) 2015年六月 &(15) 2015年五月 &(23) 2015年四月 &(14) 2015年三月 &(22) 2015年二月 &(15) 2015年一月 &(24) 2014年十二月 &(13) 2014年十一月 &(16) 2014年十月 &(19) 2014年九月 &(19) 2014年八月 &(18) 2014年七月 &(20) 2014年六月 &(21) 2014年五月 &(24) 2014年四月 &(17) 2014年三月 &(29) 2014年二月 &(22) 2014年一月 &(22) 2013年十二月 &(24) 2013年十一月 &(20) 2013年十月 &(18) 2013年九月 &(16) 2013年八月 &(16) 2013年七月 &(20) 2013年六月 &(21) 2013年五月 &(19) 2013年四月 &(18) 2013年三月 &(24) 2013年二月 &(21) 2013年一月 &(18) 2012年十二月 &(24) 2012年十一月 &(18) 2012年十月 &(17) 2012年九月 &(17) 2012年八月 &(18) 2012年七月 &(26) 2012年六月 &(36) 2012年五月 &(36) 2012年四月 &(28) 2012年三月 &(46) 2012年二月 &(23) 2012年一月 &(15) 2011年十二月 &(27) 2011年十一月 &(59) 2011年十月 &(19) 2011年九月 &(16) 2011年八月 &(46)}

我要回帖

更多关于 maven war plugin作用 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信