当前位置: 移动技术网 > IT编程>开发语言>Java > 非mvn项目转为mvn项目并构建mvn私服

非mvn项目转为mvn项目并构建mvn私服

2019年06月05日  | 移动技术网IT编程  | 我要评论

非mvn项目转为mvn项目并构建mvn私服

 

一.背景

  公司里的系统是老系统,没有使用mvn,但是现在准备使用持续集成(ci),就要用到mvn,所以现在需要将老项目转为mvn项目,并且非mvn项目也是不好构建和拓展的。

  构建自己的mvn私服,是因为项目里面有一些jar是在中央仓库里面无法下载的,所以我需要在公司的服务器上构建自己的私服仓库,并把这些jar传到私服上。

 

二.非mvn项目转mvn项目

 

  1.非mvn和mvn项目最直观的区别当然是pom.xml了,所以现在我们需要在项目上自己创建一个pom文件.

  2.我使用的是idea工具,我直接右键pom文件,add mvn项目即可,其余的事就是工具的事情了.

  3.现在需要把以前的项目的jar全部写在pom文件里面,这里面的水还是比较深的,首先jar就比较多,其次是很多可能你找不到什么的,或者依赖版本的问题,反正这个要花一定的时间。

    当你发现有一部分jar包在mvn中央仓库里面怎么都找不到,你可能要意识到这个jar包可能本来就没有,所以需要我们使用私服来上传自己的jar文件。

 

 

三.私服的安装

  1.在网站下载免费版的nexus::

  

    根据自己项目需求选择版本2还是版本3,下载成功过后,自己安装。安装成功启动过后就可以在页面上看到下面的信息了:

    

     初始的登录账号/密码是:admin/admin123,端口8080,都是可以在config配置里面自己修改的,这里就不多说了。

 

 

四.配置项目

 

  1.修改本地mvn仓库和mvn的settings.xml

 

  找到你所安装使用的mvn插件,在安装路径里的config里面的settings.xml文件进行修改:

   

<servers>
    <!-- server
     | specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | note: you should either specify username/password or privatekey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentrepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    <server>
        <id>central</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    <server>
        <id>thirdparty</id>
        <username>admin</username>
        <password>admin123</password>
    </server>

    <!-- another sample, using keys to authenticate.
    <server>
      <id>siteserver</id>
      <privatekey>/path/to/private/key</privatekey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

   

<mirrors>
    <!-- mirror
     | specifies a repository mirror site to use instead of a given repository. the repository that
     | this mirror serves has an id that matches the mirrorof element of this mirror. ids are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorid</id>
      <mirrorof>repositoryid</mirrorof>
      <name>human readable name for this mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
    
     -->
     <mirror>
        <id>nexus-releases</id>
        <url>http://192.168.50.191:8081/nexus/content/groups/public/</url>
        <mirrorof>*</mirrorof>        
    </mirror>
    <mirror>
        <id>nexus-snapshots</id>
        <url>http://192.168.50.191:8081/nexus/content/groups/public//</url>
        <mirrorof>*</mirrorof>        
    </mirror>
  </mirrors>

  在pom文件里面添加:

  

    <repositories>
        <repository>
            <id>central</id>
            <name>central</name>
            <url>http://192.168.50.191:8081/nexus/content/repositories/central/</url>
        </repository>
        <repository>
            <id>thirdparty</id>
            <name>3rd party</name>
            <url>http://192.168.50.191:8081/nexus/content/repositories/thirdparty/</url>
        </repository>
    </repositories>

 

 

五.上传jar包到mvn私服

 

  这里面有2种方式(命令和页面操作)

  1.页面操作

  

    这个就不用多说了,就是界面点点点

 

  2.命令上传

 

    在你的项目pom文件目录,cmd执行上传:

  

mvn deploy:deploy-file -dgroupid=com.fh -dartifactid=servlet-api -dversion=1.0 -dpackaging=jar -dfile=e:\workspace\bpm\webroot\web-inf\lib\servlet-api.jar -durl=http://192.168.50.191:8081/nexus/content/repositories/thirdparty/ -drepositoryid=thirdparty

 

 

  mvn私服是公司里面必备的技能之一,可以多多学习下。

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网