开发者社区> 问答> 正文

在Maven配置了OSC的库以后,工程pom中配置的repository不会被使用了:配置报错 

如题,环境是Win,Eclipse4.4.0 EE x64 内置的m2e插件,在公共settings.xml中根据 教程 添加了OSC的库;在项目POM中配置了本地库:

<repositories>
  <repository>
    <id>local</id>
    <name>Local Central Repo</name>
    <url>http://xx.xx.xx.xx:8081/nexus/content/repositories/public/</url>
    </repository>
</repositories>
运行 maven install,Maven不会去下载这个本地库里面的包,去掉OSC的公共库后就可以了,但是其他库用的就是maven的官方库了。

请问怎样配置才能够让我即用本地库又用OSC的库呢?

展开
收起
kun坤 2020-06-02 16:48:28 682 0
1 条回答
写回答
取消 提交回答
  • 你是用的OSC提供的settings.xml文件吗?如果是,需要改改。

    在settings.xml中配置远程仓库与pom.xml中有所不同,它需要在<profiles>标签里面配置<repository>,这一步你做了,但除此之外,还要将所配置的<profiles>激活,即在该标签同级别的位置加上激活标签:

    <profiles>
      <profile>
          <id> myProfile1 </id>
         <repositories>
           <repository>
             <id>local</id>
             <name>Local Central Repo</name>
             <url>http://xx.xx.xx.xx:8081/nexus/content/repositories/public/</url>
           </repository>
         </repositories>
      </profile>
      <profile>
        <id>myProfile2</id>
        .......
      </profile>
    </profiles>
    <activeProfiles>
      <activeProfile>myProfile1</activeProfile>
      <activeProfile>myProfile2</activeProfile>
    </activeProfiles>
    还有一种简单的,就是换种激活方式,不用<activeProfiles>,而是在你自己定义的<profile>中加入一个子标签<activation>,比如OSC提供的:
    <activation>
        <jdk>1.4</jdk>
    </activation>
    这个就是指激活条件:JDK版本必需为1.4,很显然这个版本没有谁在用了吧,所以激活不了,自己改下就好了,或者设置一个区间值: <jdk>[1.4,1.7)</jdk>,你懂的。 如果你觉得还太麻烦,有第三种方法,就直接在你的<profile>中无条件默认激活:
    <activation>
       <activeByDefault>true</activeByDefault>
    </activation>
    啰嗦较多呵,简单讲就上面三种常用方式,希望对你有用,记得好评哈哈 ###### @阿J小虫,我在setting.xml 中配置的就是在 mirrors 中添加了一些东西,如下:
    <mirrors>
           <mirror>
    		<id>nexus-osc</id>
    		<mirrorOf>*</mirrorOf>
    		<name>Nexus osc</name>
    		<url>http://maven.oschina.net/content/groups/public/</url>
    	</mirror>
    </mirrors>
    然后项目 pom.xml 中添加了主题中说的配置。结果如主题中所说的不能使用 pom.xml 配置的 repository,运行 maven install 时不会去查找 pom.xml 中配置的库。 你的意思是在工程 pom.xml 中添加:
    <activeProfiles>
      <activeProfile>local</activeProfile>
    </activeProfiles>
    <activation>
        <jdk>[1.4,1.7)</jdk>
    </activation>
    <activation>
       <activeByDefault>true</activeByDefault>
    </activation>
    就可以解决我的问题了?######不是在pom.xml,而是settings.xml
    2020-06-02 16:48:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
使用Spring.Initializr定制工程脚手架 立即下载
陈曦:使用Spring.Initializr定制工程脚手架 立即下载
低代码开发师(初级)实战教程 立即下载