eclipse android使用Maven deploy构建到Nexus上

过程如下:

1  安装Maven 、 eclipse 、 Nexus

2  Maven配入Nexus仓库地址

1)修改Maven settting.xml文件        (常见默认路径:C:\Users\Administrator\.m2)

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  3.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  5. <localRepository>D:\Repositories\BeijingMaven\</localRepository>  
  6. <pluginGroups></pluginGroups>   
  7. <proxies></proxies>   
  8. <servers>  
  9.  <server>  
  10.       <id>Demo-Snapshot</id>  
  11.       <username>cj</username>  
  12.       <password>123456</password>  
  13.     </server>  
  14. </servers>   
  15. <mirrors>   
  16.      <mirror>    
  17.         <id>cj-nexus</id>    
  18.         <name>cj internal nexus repository</name>  
  19.         <url>http://192.168.3.10:88/nexus/content/groups/public/</url>    
  20.         <mirrorOf>central</mirrorOf>    
  21.     </mirror>  
  22. </mirrors>   
  23. <profiles>   
  24.      <profile>    
  25.         <id>dev</id>    
  26.         <repositories>    
  27.           <repository>    
  28.             <id>cj-nexus</id>    
  29.             <url>http://192.168.3.10:88/nexus/content/groups/public/</url>    
  30.             <releases>    
  31.               <enabled>true</enabled>    
  32.             </releases>    
  33.             <snapshots>    
  34.               <enabled>true</enabled>    
  35.             </snapshots>    
  36.           </repository>    
  37.         </repositories>    
  38.       </profile>    
  39. </profiles>   
  40.  <activeProfiles>    
  41.       <activeProfile>dev</activeProfile>    
  42.     </activeProfiles>  
  43. </settings>  

注:http://192.168.3.10:88/nexus/content/groups/public/  为Demo(Maven android项目)配置的公共的仓库组group,存储公共的JAR包,可以不用配置

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. localRepository本地MAVEN仓库存放JAR包的位
  2. D:\Repositories\BeijingMaven\</span>  

 

3 eclipse  配置

1)eclipse 内 Demo项目:

 pom.xml配置,指定Nexus 私服主仓库 hosted  ,如下:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <distributionManagement>  
  2.         <repository>  
  3.             <id><span style="background-color: rgb(255, 0, 0);">Demo-Release</span></id>  
  4.             <name>Demo Release Repository</name>  
  5.             <url><span style="color:#FF6666;">http://192.168.3.10:88/nexus/content/repositories/Demo-Release/</span></url>  
  6.         </repository>  
  7.         <snapshotRepository>  
  8.             <id><span style="color:#CC0000;">Demo-Snapshot</span></id>  
  9.             <name>Demo Snapshot Repository</name>  
  10.             <url><span style="color:#FF0000;">http://192.168.3.10:88/nexus/content/repositories/Demo-Snapshot/</span></url>  
  11.         </snapshotRepository>  
  12. </distributionManagement>   
  13.   
  14. 2)eclipse 内Maven项<span style="color:#FF0000;"></span>配置  
    window -> Preferences -> Maven  -> User settings ,选中User settings,(即 Maven settting.xml文件路径位置,

常见默认路径:C:\Users\Administrator\.m2\settting.xml )       ,      操作如图1:

  


4 将Demo项目部署到Tomcat v6.0 Server 内,启动Server,完成项目的运行(Maven、eclipse会分别根据settting.xml、pom.xml去远程私服下载公共的JAR包、

主仓库 hosted 内全部JAR包,存放位置为:本地MAVEN仓库位置:D:\Repositories\BeijingMaven\


二:eclipse 使用Maven deploy命令部署构建到Nexus上,(只测试过‘项目JAR’部署、构建)

 应用场景:SYS-UTIL(系统工具)项目部署、构建成JAR包(SYS-UTIL-1.0.0.jar)存储到Nexus私服上,以供其它项目(依赖)使用


过程如下:

1) 创建SYS-UTIL(系统工具)项目,即Maven 项目

2     配置SYS-UTIL(系统工具)项目POM.xml文件,指定项目存储的Nexus URL 位置(具体可参考上面配置)

3)  右击项目,依次执行:Run As --> Run Configurations ---> Maven Build --->New _Configuration(双击Maven Build可生成) -->  Browse Workspace 选中项目,

Goals输入 : deploy -e      后,点击 Run

如图2:


4)SYS-UTIL(系统工具)项目会重新构建生成JAR包,并生成、并更新当已存在此JAR包时)远程Nexus仓库



提交到nexus时候报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

原来是没有配置认证。

maven目录conf的setting.xml里,

  1.    < server >   
  2.     < id > releases </ id >   
  3.     < username > admin </ username >   
  4.     < password > admin123 </ password >   
  5.   </ server >   
  6.  < server >   
  7.   < id > snapshots </ id >   
  8.   < username > admin </ username >   
  9.   < password > admin123 </ password >   
  10.   </ server >   
  11. </ servers >   

用户名和密码都是nexus的。再次deploy即可。

注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

  1. <!-- 配置远程发布到私服,mvn deploy -->   
  2.     < distributionManagement >   
  3.         < repository >   
  4.             < id > releases </ id >   
  5.             < name > Nexus Release Repository </ name >   
  6.             < url > http://10.1.81.199:8081/nexus/content/repositories/releases/ </ url >   
  7.         </ repository >   
  8.         < snapshotRepository >   
  9.             < id > snapshots </ id >   
  10.             < name > Nexus Snapshot Repository </ name >   
  11.             < url > http://10.1.81.199:8081/nexus/content/repositories/snapshots/ </ url >   
  12.         </ snapshotRepository >   
  13.     </ distributionManagement >   




如果这里不配置,会报错: 报 错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter



参照:http://blog.csdn.net/jun55xiu/article/details/39671907

         http://comeonbabye.iteye.com/blog/1742506

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值