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

标签 java git maven

我在我创建的 git 存储库中为我的文件提供了 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 导入一个额外的 graphframes jar ,其依赖关系如下:
https://mvnrepository.com/artifact/graphframes/graphframes/0.5.0-spark2.1-s_2.11

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

最佳答案

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

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

2) 中央存储库:它是所有项目相关依赖项的集中位置,需要在 setting.xml 文件中提供它的位置。 我希望您已经在setting.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).

关于java - 除了 git repo 中的 jar 之外,还从 mvn repo 导入依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46467203/

相关文章:

java - java是否有一个不会为坏数据抛出异常的int.tryparse?

maven - 将 Enunciate 与 Maven/多个模块一起使用

java - Maven 在 Ubuntu 12.04、JDK1.7 上构建失败

java - 使用 ProGuard 和 Maven 混淆 Java 代码 : Test classes and ClassNotFoundError

java - 当客户端调用 html 或 jsp 页面时,是否可以选择登录凭据的窗口

java - 无法在 linux 上安装 rjb1.4.9 指出未设置 java_home

java - 自定义 JSF validator 中的消息格式

git - 在 GitHub 中包含第三方非 GitHub 库

git - 使用 scm-maven-plugin 时如何在 pom 中指定提交消息?

git - 如何修复由于删除分支中的文件而导致的 merge 冲突?