简体   繁体   English

如何使M2E(Eclipse的Maven集成)知道在哪里找到依赖项?

[英]How to make m2e (maven integration for eclipse) know where to find dependencies?

When work in STS (springsource tool suite), open pom.xml file and check dependencies in "dependencies tab", add/select maven dependency will give 0 result found. 在STS(springsource工具套件)中工作时,打开pom.xml文件并在“依赖项选项卡”中检查依赖项,添加/选择maven依赖项将得出0结果。 We need edit pom.xml to add dependency by hand. 我们需要编辑pom.xml来手动添加依赖项。 Is there a way to let M2E know where to check repository to search dependency? 有没有办法让M2E知道在哪里检查存储库以搜索依赖项?

By default , all pom.xml will automatically extend the Super POM , which is located in the maven_installation_folder/lib/maven-xxx-uber.jar ==> package org.apache.maven.project ==> pom-4.0.0.xml . 默认情况下,所有pom.xml都会自动扩展Super POM,它位于maven_installation_folder/lib/maven-xxx-uber.jar ==>包org.apache.maven.project ==> pom-4.0.0中。 xml All the configuration specified in the Super POM is inherited by the POMs you created for your projects. 超级POM中指定的所有配置均由您为项目创建的POM继承。

If you open pom-4.0.0.xml , you will find that the maven central repository http://repo1.maven.org/maven2/ is defined here . 如果打开pom-4.0.0.xml ,则会发现在此处定义了maven中央存储库http://repo1.maven.org/maven2/ That means if you specify a <dependency> in your pom.xml , maven will try to download this dependency in the following orders: 这意味着,如果您在pom.xml中指定<dependency> ,则maven将尝试按以下顺序下载此依赖项:

  1. Maven local repository (ie your local hard disk) Maven本地存储库(即您的本地硬盘)
  2. Maven central repository specifed in the Super POM (ie http://repo1.maven.org/maven2/ ) 在超级POM中指定的Maven中央存储库(即http://repo1.maven.org/maven2/
  3. Maven remote repository (Defined in the <repository> section of your pom.xml ) Maven远程存储库(在pom.xml<repository>部分中定义)

Normally , I will use some maven repository search engines , such as this , to find out the <dependency> of the libraries /frameworks /tools that I want to use and then paste them in the pom.xml 通常,我将使用一些Maven存储库搜索引擎(例如this )来查找要使用的库/ frameworks / tools的<dependency> ,然后将其粘贴到pom.xml中。

If the dependency exists in the Maven central repository , everything will be fine and it will be download to your local repository . 如果该依赖关系存在于Maven中央存储库中,那么一切都会很好,并将其下载到本地存储库中。 However , if some of the <dependency> (eg Hibernate) cannot be found and downloaded from the Maven central repository , you can try to visit its official site to find out its repository link and paste them in the <repository> section of your pom.xml .For example , Hibernate require to define the jboss repository in the pom.xml like this: 但是,如果找不到某些<dependency> (例如Hibernate)并从Maven中央存储库下载,则可以尝试访问其官方站点以查找其存储库链接,并将其粘贴到pom<repository>部分中。 .xml 。例如,Hibernate需要在pom.xml中定义jboss存储库,如下所示:

<repositories>
        <repository>
            <id>repository.jboss.org</id>
            <name>JBoss Repository</name>
            <url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
           <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>     
        </repository>        
 </repositories>

You can refer to this for the use of <repository> 您可以参考为使用<repository>

M2e by default searches maven central repository for artifacts. 默认情况下,M2e在Maven中央存储库中搜索工件。 It downloads an index file which has artifact details. 它下载一个包含工件详细信息的索引文件。 You can configure additional repositories to be searched by specifying the same in repository section of your settings.xml file. 通过在settings.xml文件的“ 存储库”部分中指定相同的存储库,可以配置要搜索的其他存储库。 Do note that some repositories do not have this index file. 请注意,某些存储库没有此索引文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM