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

不如把源码上传到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教程:进击机器学习(五)--Scipy《转》

    Scipy简介 文件输入和输出scipyio 线性代数操作scipylinalg 快速傅里叶变换scipyfftpack 优化器scipyoptimize 统计工具scipystats Scipy简介 ...

  2. centos7将可执行程序做成服务

    1.systemctl 用法:systemctl [OPT] COMMAND [NAME]…启动服务:systemctl start NAME.service停止服务:systemctl stop N ...

  3. css3属性box-sizing:border-box 用法解析

    响应式Web设计经常需要我们通过百分比设置组件宽度.如果我们不考虑边框,那么很容易就可以实现,但如果你给每一列以及总宽度都采用百分比设置,那这个时候固定的边框大小就会出来捣乱.下面我们将看到一组方法去 ...

  4. 使用fdisk进行分区

    fdisk进行分区 1.首先使用fdisk -l 发现待分区磁盘/dev/vdb  大小为1TB 2.fdisk /dev/vdb 对该磁盘进行分区,输入m并回车 3.输入n并回车,n是“new”新建 ...

  5. C++ 日志生成 DLL

    示例: #define log_dbg(format,args...) \        printf("[DBG] [%s: %s() line:%d]: "format ,__ ...

  6. CSS: Grid homework redact.

    The web homework: Finished design: (I use six block with different color to show this homework and I ...

  7. 2D射影空间,为何引入射影空间

    2D欧氏空间R2中,点的表示是A(x1,y1), B(x2,y2),二维参数,线的表示是L: y=kx+b,是二维参数: 如何表示点在线上面?可以扩展为(k,-1,b)* (x1,y1,1)t = 0 ...

  8. angular中使用ckplayer播放器

    原文地址:https://www.cnblogs.com/jying/p/9519557.html ,转载请说明出处. ckplayer官网:http://www.ckplayer.com 使用ckp ...

  9. 在ASP.NET MVC中使用UEditor无法提交的解决办法

    很简单的一个ajax提交,却怎么都不成功 $.ajax({ type: "POST", url: "/mms/riskmanage/commitreply", ...

  10. 【Django】数据迁移问题

    最近发现,Django在修改models之后重新生成迁移文件(这里可以生成),再进行数据库迁移的时候老是出错,查询数据库时老是找不到表格或者字段. 尝试过重新新建项目,新建一个同名APP,然后mode ...