maven搭建私服,使用idea创建项目(遇到的一些坑)

1.解压nexus

2.覆盖原始的nexus索引文件

  先清空  sonatype-work\nexus\indexer\central-ctx文件夹下的所有文件

使用如下文件替换(不知道怎么上传这些文件,应该百度得到吧。。。)

3.修改maven的setting.xml

  1)设置本地仓库

<localRepository>D:/maven/respository</localRepository>

  2)修改镜像地址,本地maven直接连接私服Nexus

  下面内容添加到<mirrors>标签中

 

    <mirror>     

      <id>nexus-releases</id>     

      <mirrorOf>*</mirrorOf>     

      <url>http://localhost:8081/nexus/content/groups/public</url>     

    </mirror>

     <mirror>     

       <id>nexus-snapshots</id>     

      <mirrorOf>*</mirrorOf>     

       <url>http://localhost:8081/nexus/content/repositories/apache-snapshots/</url>     

     </mirror>

  3)设置profiles

<profile>

<id>nexusTest</id>

<repositories>

<repository>

<id>local-nexus</id>

<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>

<releases>

<enabled>true</enabled>

</releases>

<snapshots>

<enabled>true</enabled>  

</snapshots> 

</repository>

</repositories>

</profile>

  4)设置JDK版本

<profile>

<id>jdk-1.7</id>

<activation>

<activeByDefault>true</activeByDefault>

<jdk>1.7</jdk>

</activation>

<properties>

<maven.compiler.source>1.7</maven.compiler.source>

<maven.compiler.target>1.7</maven.compiler.target>

<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>

</properties>

</profile>

 

  5)激活<profile>内容

<!--激活id为nexusTest的profile-->

<activeProfiles>

<activeProfile>nexusTest</activeProfile>

</activeProfiles>

 

 6)在servers标签中配置

<server>  

<!--<id>的值必须和pom.xml中<id>对应 -->

        <id>releases</id>  

        <username>admin</username>  

        <password>admin123</password>  

      </server>  

      <server>  

        <id>snapshots</id>  

        <username>admin</username>  

        <password>admin123</password>  

      </server>  

 

4.修改项目的pom.xml文件(这一步里的<id>标签里的值与 setting,xml里的server标签里的<id>值对应,目的是将自己的项目发布到私服中,自动对应版本,无需登录)

<distributionManagement>

  <repository>

    <id>releases</id>

    <url>http://localhost:8081/nexus/content/repositories/releases</url>

  </repository>

 <snapshotRepository>

    <id>snapshots</id>

    <url>http://localhost:8081/nexus/content/repositories/snapshots</url>

  </snapshotRepository>

</distributionManagement>

 

到此,私服搭建完成。开启nexus服务,并运行nexus,然后可以通过localhost:8081/nexus查看(端口号可改,默认8081)

最后使用IDEA创建了一个maven项目,随意的添加了一些depedependency,直接报错,提示 Dependency ‘xxxxx’ not found

原因:可能是网络问题,也可能是缺少了一个nexus-maven-repository-index.properties文件

解决:将nexus-maven-repository-index.properties文件也复制一份到 sonatype-work\nexus\indexer\central-ctx下;

然后到maven仓库下使用win文件查找 *.lastUpdated,将找到的删除。

最好是使用代理翻墙一下,然后打开IDEA的setting,找到maven下的repository

找到右侧的之前在setting.xml下配置的url,然后update,等待一会(如果没有翻墙的话可能会失败,像第三个粉红的那个,是被我qianggua强关的)

最最最后,找到IDEA右侧的maven project,reimportyi一下就好了(或者直接在pom.xml上右键,maven-》reimport也可以)

 

(ps:写这个贴是为了记录一下爬坑的过程!文中的搭建方法、遇到方法题以及解决方法不一定适合所有人,但是希望能有所帮助)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值