除了git repo中的jar之外,还从mvn repo导入依赖项

时间:2017-09-28 10:45:54

标签: java git maven

我在git repo中为我的文件提供了jar文件我创建了pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.acc.ar</groupId>
        <artifactId>ar-anal-plat</artifactId>
        <version>1.6.0-RC-SNAPSHOT</version>
    </parent>
    <artifactId>gr-anal-app</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.acc.ar</groupId>
            <artifactId>ar-anal-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.acc.ar</groupId>
            <artifactId>ar-anal-core-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

我想从具有依赖关系的mvn repo导入另一个图形框架,如下所示:
https://mvnrepository.com/artifact/graphframes/graphframes/0.5.0-spark2.1-s_2.11

我必须在pom文件中进行哪些更改?

2 个答案:

答案 0 :(得分:1)

maven中有3种类型的存储库:

1)本地存储库本地系统上的一个位置,用于在第一时间从中央或远程存储库存储下载的jar,从第二次开始依赖关系在本地存储库中搜索首先如果不存在则转到中央回购:它的位置需要在maven的setting.xml文件中提及。

2)中央存储库:它是所有与项目相关的依赖项的集中式存储,它的位置需要在setting.xml文件中提供。 我希望你在settings.xml文件中已经提到了“git repo”。

3)远程存储库:如果本地或中央存储库中不存在任何依赖关系,则可以在pom.xml文件中提供自定义位置。所以,首先它将调查本地回购,如果不存在,那么中央回购然后远程回购。

<repositories>
  <repository>
     <id>companyname.lib1</id>
     <url>http://download.companyname.org/maven2/lib1</url>
  </repository>
  <repository>
     <id>companyname.lib2</id>
     <url>http://download.companyname.org/maven2/lib2</url>
  </repository>

在你的情况下使用它,我猜你的问题应该得到解决。

搜索顺序:

Step 1 − Search dependency in local repository, if not found, move to step 2 else perform the further processing.

Step 2 − Search dependency in central repository, if not found and remote repository/repositories is/are mentioned then move to step 4. Else it is downloaded to local repository for future reference.

Step 3 − If a remote repository has not been mentioned, Maven simply stops the processing and throws error (Unable to find dependency).

Step 4 − Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference. Otherwise, Maven stops processing and throws error (Unable to find dependency).

答案 1 :(得分:0)

在依赖项块中,您需要插入以下内容:

   <!-- https://mvnrepository.com/artifact/graphframes/graphframes -->
   <dependency>
       <groupId>graphframes</groupId>
       <artifactId>graphframes</artifactId>
       <version>0.5.0-spark2.1-s_2.11</version>
   </dependency>

然后很可能在IDE /导入更改中刷新项目。

相关问题