转载于:http://blog.csdn.net/jerome_s/article/details/54410178

 
        Maven获取jar的默认顺序是
        
        1. Releases 在发布库里面查找(主要用于稳定版)
        2. Snapshots 在快照库里面查找(和上面的区别就是在pom加了个<version>0.0.5-SNAPSHOT</version>,主要用于开发阶段)
        3. 3rd party 不是我们自己开发的,也在中央库找不到的,就要到这里手动上传包到私服。
        4. Central 到中央库查找。
 
 

上传私服 pom.xml 配置

1
2
3
4
5
6
7
8
9
10
<distributionManagement >
    <repository >
        <id >releases </id >
   </repository >
   <snapshotRepository >
        <id >Snapshots </id >
   </snapshotRepository >
</distributionManagement 
 
        settings.xml 配置
1
2
3
4
5
6
7
8
9
10
11
12
<servers>
    <server
       <id>releases</id
       <username>admin</username
       <password>qsapwd</password
    </server
    <server
       <id>Snapshots</id
       <username>admin</username
       <password>qsapwd</password
    </server>  
</servers
        
        打包源码 pom.xml 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<build>
        <plugins>
            <plugin<!-- 打jar包 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <excludes>
                        <exclude>**/*.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin<!-- 打源码 -->
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-source-plugin</artifactId>  
               <version>2.4</version>
                <configuration>  
                    <attach>true</attach>  
                </configuration>  
                <executions>  
                    <execution>  
                        <phase>compile</phase>  
                        <goals>  
                            <goal>jar</goal>  
                        </goals>  
                    </execution>  
                </executions
            </plugin> 
        </plugins>
    </build>
 
Maven 打源码包,并上传私服

 
        1. 使用命令行
 
        cmd 进入到项目根目录执行:mvn clean source:jar package 会生成两个jar,其中有一个是源码的jar,分别使用相同的groupId和artifactId。
 
        也可以直接,打包并上传私服,使用命令:deploy -e
 
        2. 使用Eclipse
 
        右击项目 Run as →Maven bulid,在Goals输入deploy -e。
        

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

一个基础类,可能要升级并放到私服库里,为了方便,应该能够自动打包放到nexus。这就需要配置maven一些参数与pom.xml。

依次在settings.xml文件裡輸入

  1. <!-- nexus帳號和密碼-->
  2. <server>
  3. <id>releases</id>
  4. <username>admin</username>
  5. <password>admin123</password>
  6. </server>
  7. <server>
  8. <id>snapshots</id>
  9. <username>admin</username>
  10. <password>admin123</password>
  11. </server>
  12. </servers>
  13. ...
  14. <!-- 引用naxus倉庫組-->
  15. <profile>
  16. <id>dev</id>
  17. <repositories>
  18. <repository>
  19. <id>nexus</id>
  20. <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
  21. <releases>
  22. <enabled>true</enabled>
  23. </releases>
  24. <snapshots>
  25. <enabled>true</enabled>
  26. </snapshots>
  27. </repository>
  28. </repositories>
  29. <pluginRepositories>
  30. <pluginRepository>
  31. <id>nexus</id>
  32. <url>http://127.0.0.1:8081/nexus/content/groups/public</url>
  33. <releases>
  34. <enabled>true</enabled>
  35. </releases>
  36. <snapshots>
  37. <enabled>true</enabled>
  38. </snapshots>
  39. </pluginRepository>
  40. </pluginRepositories>
  41. </profile>
  42. ..
  43. <!-- nexus -->
  44. <activeProfiles>
  45. <activeProfile>dev</activeProfile>
  46. </activeProfiles>

注意:根據標籤位置準確輸入

在本项目的pom.xml配置即可 
<!--上传配置 必须-->

<distributionManagement>
<repository>
<id>releases</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<!--上传source.jar 非必须-->

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-source-plugin</artifactId>

<executions>

<execution>

<id>attach-sources</id>

<goals>

<goal>jar</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

上面的ID和pom.xml中对应distributionManagement-> repository的ID,用户名和密码需要在nexus中配置。

完成以上配置,只要输入命令:mvn deploy 即可。

遇到的问题:

maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized

提交到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>

Maven 自动打包上传到私服 Nexus的更多相关文章

  1. maven自动打包上传nexus仓库配置

    一个基础类,可能要升级并放到私服库里,为了方便,应该能够自动打包放到nexus.这就需要配置maven一些参数与pom.xml. 依次在settings.xml文件裡輸入 <!-- nexus帳 ...

  2. 如何将maven项目打包上传到私服

    比如我们想要把项目通过maven生产源码包和文档包并发布到自己的私服上,有两个maven插件可以做到这些工作,一个是maven-source-plugin,另一个是maven-javadoc-plug ...

  3. Maven配置jar(war)包自动打包上传Maven服务器的配置

    Maven配置jar(war)包自动打包上传Maven服务器的配置 创建jar(war)包工程 创建一个maven工程 在工程中穿件一个测试类 配置pom.xml <distributionMa ...

  4. iOS开发进阶 - 使用shell脚本自动打包上传到fir.im上-b

    用fir.im测试已经好长时间了,感觉每次打包上传都很麻烦,想着是不是可以用脚本自动打包,在网上搜了一下确实有,下面总结一下如何使用脚本自动打包上传到fir.im,以及打包过程中遇到的问题和解决办法 ...

  5. 修改jar包内容并打包上传到私服

    第一步:拉下git分支中代码,进行修改,修改后commit——>push 第二步:在IDEA中Terminal中执行命令进行打包到本地mvn clean package 第三步:上传到私服,方法 ...

  6. IDEA maven 项目如何上传到私服仓库

    前言:idea maven 发布版本到私服(快照和正式版).我有个项目( jar 包源码),其他 maven 项目能直接引入依赖就最好了,所以必须将这个 jar 包源码发布到 maven 私服仓库里去 ...

  7. 使用shell脚本自动打包上传 fir.im

    http://blog.csdn.net/wang631106979/article/details/52299083

  8. xcodebuild自动打包上传到蒲公英的shell脚本

    注意: ExportOptions.plist (包含了证书相关信息) 该plist 文件可以通过xcode手动导出ipa之后获取到, 区分appstore 和 development的情况 #! / ...

  9. 在pom.xml中使用distributionManagement将项目打包上传到nexus私服

    本文介绍 如何在pom.xml中使用distributionManagement将项目打包上传到nexus私服 1.pom.xml文件添加distributionManagement节点 <!- ...

随机推荐

  1. Kruskal算法-HDU1863畅通工程

    链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1863] 题意 Problem Description 省政府"畅通工程"的目标是使全 ...

  2. 实践简单的项目WC

    #include<iostream> #include<fstream> #include<string> #include<Windows.h> us ...

  3. Notes of Daily Scrum Meeting(12.24)

    平安夜了,我们还在这里辛苦地赶代码,整个人都不好了... 今天的团队任务总结如下: 团队成员 今日团队工作 陈少杰 寻找大神帮助,调试网络连接 王迪 建立搜索的UI界面,把算法加入进去 金鑫 调试网络 ...

  4. 【Beta阶段】第八次Scrum Meeting!

    每日任务内容: 本次会议为第八次Scrum Meeting会议~ 由于本次会议项目经理身体不适,未参与会议,会议精神由卤蛋代为转达,其他同学一起参与了会议 队员 昨日完成任务 明日要完成任务 刘乾 今 ...

  5. Linux内核分析 笔记五 扒开系统调用的三层皮(下) ——by王玥

    (一)给MenuOs增加time和time-asm命令 更新menu代码到最新版 在main函数中增加MenuConfig 增加对应的Ttime和TimeAsm函数 make rootfs (二)使用 ...

  6. 《Linux内核分析》第八周:进程的切换和系统的一般执行过程

    杨舒雯(原创作品转载请注明出处) <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验目的: 使用gdb ...

  7. [转帖]Nginx的超时keeplive_timeout配置详解

    Nginx的超时keeplive_timeout配置详解 https://blog.csdn.net/weixin_42350212/article/details/81123932   Nginx  ...

  8. Qt__QWidget::update()与Qwidget::repaint()的区别

    QT事件的产生 1.操作系统产生 操作系统将获取的事件,比如鼠标按键,键盘按键等keyPressEvent,keyReleaseEvent,mousePressEvent,mouseReleaseEv ...

  9. file_put_contents () failed to open stream: Permission denied 解决办法

    今天,帮朋友配置服务器thinkphp5的时候,直接访问“www.***.com/admin/index/index” : 出现以下错误: file_put_contents (/PHP/admin/ ...

  10. Angular injector注入器

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...