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

不如把源码上传到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. MDI容器

    MDI容器 具体步骤如下: private void 销售ToolStripMenuItem_Click(object sender, EventArgs e) { VisibledForm(); F ...

  2. 【亲测】502 Bad Gateway 怎么解决?

    502 Bad Gateway 怎么解决? 1.什么是502 badgateway 报错 简单来说 502 是报错类型代码,bad gateway 错误的网关. 2.产生错误的原因 连接超时 具体原因 ...

  3. LINUX 中实现逻辑卷、自动挂载

    实验项目: 准备3块10G的空闲分区,将类型ID修改为8e(LVM) 使用其中2块分区组建名为myvg的卷组,查看此卷组信息 先检查有哪些物理卷 讲两块空闲分区转换成物理卷 再检查有哪些物理卷,查看其 ...

  4. 纯Java——简易高并发框架

    转自:https://blog.csdn.net/MonkeyDCoding/article/details/81369610 0.源代码github-简易高并发框架 注:本篇博客知识来自于网课. 1 ...

  5. Django之form模板的使用

    form模块的简介与用处 1.form 是前后端交互的一种方式, form表单提交的一种,django中有一个模块是form他主要用处就过滤前端form提交的数据 1. forms 模块是处理前后台的 ...

  6. ODPS SQL <for 数据操作语言DML>

    基本操作: 查询: SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_co ...

  7. nginx的一次工作记录

    upstream fazhi_ui{ server ; } upstream fazhi_api{ server ; } server { listen ; server_name localhost ...

  8. EntityFrameworkCore DBFirst

    需要引用如下nuget包 Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityF ...

  9. Process 开启子进程 的两种方式、join控制子进程、守护进程

    一.join控制子进程的一种方式 当主进程需要在子进程结束之后结束时,我们需要用到join来控制子进程. import time import random from multiprocessing ...

  10. 微信小程序 验证码倒计时组件

    https://blog.csdn.net/susuzhe123/article/details/80032224