有时候我们会使用第三方包到我们的项目中,但是想看源码的时候,需要下载源码查看,十分麻烦。

不如把源码上传到maven私服中,这样查看源码的时候就可以直接从mvaen nexus下载直接查看了。

方法如下:

1、在setting.xml文件中增加用户名和密码配置(特别注意这里的ID)

    <servers>
<!-- 用于发布正式版本 -->
<server>
<id>maven-repository-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<!-- 用于发布快照版本 -->
<server>
<id>maven-repository-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

2、在项目的pom.xml中增加以下内容

    <build>
<plugins>
<!-- 要将源码放上去,需要加入这个插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> <distributionManagement>
<repository>
<!-- 这里的ID要和setting的id一致 -->
<id>maven-repository-releases</id>
<url>http://ip:8081/nexus/content/repositories/thirdparty/</url>
</repository>
<!--这是打成快照版本的配置,如果不用这个snapshotRepository标签,打包失败,会报权限问题 -->
<snapshotRepository>
<id>maven-repository-snapshots</id>
<url>http://ip:8081/nexus/content/repositories/thirdparty</url>
</snapshotRepository>
</distributionManagement>

3.执行Maven build的deploy命令

正常情况下,如果是发布新版本的话,一切是ok的。

4.如果是替换老版本,可能会出现如下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project YourProject: Failed to deploy artifacts: Could not transfer artifact YourProject:jar:3.0.1 from/to maven-repository-releases (http://ip:8081/nexus/content/repositories/thirdparty/): Failed to transfer file: http://192.168.16.204:8081/nexus/content/repositories/thirdparty/../../YourProject.jar. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是maven deploy 已存在的包的时候出现400错误,原因是 release 默认库是不允许重复部署的。

解决: 修改maven 私服配置.

修改图中配置就可以重复部署了:Deployment Policy:Allow Redeploy

然后,重新deploy,既可以将源码和jar包一并上传到maven私服了。

5.其他可能遇到的问题

  用户权限问题,可能导致发布失败。

本文参考:http://blog.csdn.net/lzzyok/article/details/25626583f

    http://blog.csdn.net/lulongzhou_llz/article/details/42869785

发布本地项目和源码到maven私服中的更多相关文章

  1. maven项目的运行方式,maven私服的上传下载

    一.maven项目父子工程的运行方式 1.通过父项目的plugin下集成的tomacat run启动 2.通过自身项目的tomcat plugin启动,但前提是所依赖的项目必须全部都install(将 ...

  2. 怎么将本地项目放到码云(gitee)上面?图文详解

    git的好处什么的,在此就不多赘述.现在很多公司都在用git了. 那么怎么将本地已经有的项目放到码云(gitee)上呢? 前置条件说明: 1:原来项目所在位置:D:\workspace01\class ...

  3. Git上传本地项目到码云

    前提:本地安装git.注册码云 1.进入本地项目文件夹,鼠标右键代开 Git Bash Here 2.输入命令 初始化库管理文件 git init 3.输入命名 修改Git的全局配置 git conf ...

  4. 将github上的项目源码导入到eclipse中

    1.注册github帐号 在github上注册一个自己的帐号. 2.安装git插件egit 在eclipse中安装git插件egit,安装方法可以参考这篇文章: http://www.cnblogs. ...

  5. 利用git把本地项目传到github+将github中已有项目从本地上传更新

    利用git把本地项目传到github中 1.打开git bash命令行,进入到要上传的项目中,比如Spring项目,在此目录下执行git init 的命令,会发下在当前目录中多了一个.git的文件夹( ...

  6. PM2自动发布本地项目到服务器

    (一)开发环境 本地服务器 Ubunt14.04 远程服务器Ubuntu16.04 发布软件PM 2 (二)发布介绍 本地和我们的远程服务器,必须都安装有git,pm2,以及nodejs环境.实际上配 ...

  7. 码云git使用一(上传本地项目到码云git服务器上)

    主要讲下如果将项目部署到码云git服务器上,然后使用studio导入git项目,修改本地代码后,并同步到码云git上面. 首先:我们在码云上注册账号并登陆.官网(https://git.oschina ...

  8. Git发布本地项目至仓库命令行操作流程

    1.初始化项目 git init 2.创建名称为 gh-pages 新分支(若直接发布至master分支,忽略此步) git checkout --orphan gh-pages 3.把所有内容加入本 ...

  9. 上传本地项目到码云(gitee)

    1.码云上创建一个项目比如zhirong 2.本地创建一个文件夹F:\workspace\zhirong-items,进入zhirong-items打开git bash 3.执行git init ,这 ...

随机推荐

  1. python中定义的颜色

    平时学习工作中,我们经常会接触到一些大佬写的Python实用工具,运行起来总会显示出五颜六色的背景,相关的定义在matplotlib模块中,为方便使用,这里给大家展示一下在这个模块中都定义了哪些选颜色 ...

  2. django之 基于queryset和双下划线的跨表查询

    前面篇随笔写的是基于对象的跨表查询:对象.objects.filter(...)  对象.关联对象_set.all(...)  -->反向 基于对象的跨表查询例如: book_obj= Book ...

  3. django之两个使用模板的例子

    from django.db import models # Create your models here. class Book(models.Model): title=models.CharF ...

  4. 在HTML中显示base64 img 图片

    base64的图片可以直接显示在网页上面 <img src=“data:image/png;base64,******************************************** ...

  5. ORA-01219: 数据库未打开: 仅允许在固定表/视图中查询解决之道

    参考文章:https://blog.csdn.net/Trigl/article/details/50933495 解决.

  6. 李清华201772020113《面向对象程序设计(Java)》第六周学习总结

    第一部分 理论知识 1.继承 用已有类来构建新类的一种机制.新类可以继承父类的方法和域,同时可以在新类中添加新的方法和域. 已有类称为:超类.基类或父类.新类称作:子类.派生类或孩子类. 子类的构造器 ...

  7. 记号一下selenium+Firefox自动下载的参数

    参考: https://blog.csdn.net/wxstar8/article/details/80782556 https://blog.csdn.net/xiaoguanyusb/articl ...

  8. [C语言]进阶|指针与字符串

    ------------------------------------------------------------------------------------ 回顾:[C语言]指针与字符串 ...

  9. Windows Server 2008中使用计划任务定时执行BAT bat进行PHP脚本的执行

    Windows Server 2008中使用计划任务定时执行BAT bat进行PHP脚本的执行 2016年01月03日 17:36:00 持之以恒 阅读数:5520 标签: windows定时任务.b ...

  10. react-native 新手爬坑经历(unable to load script from assets 和could not connect to development server.)

    按照https://reactnative.cn/docs/0.51/getting-started.html教程新建的项目 react-native init AwesomeProject cd A ...