【问题标题】:How to use local reposity in maven?如何在maven中使用本地存储库?
【发布时间】:2016-12-02 04:36:47
【问题描述】:

我构建了公共项目并将其安装到本地存储库,然后我尝试使用相同的jar包但计算机找不到它。

首先,我将 common 构建并安装到我的本地存储库中:

F:\seprate\paymate-commons>mvn -DskipTests install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building paymate-commons 2.6.9
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ paymate-commons ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory F:\seprate\paymate-commons\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ paymate-commons ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ paymate-commons ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ paymate-commons ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.16:test (default-test) @ paymate-commons ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ paymate-commons ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ paymate-commons ---
[INFO] Installing F:\seprate\paymate-commons\target\paymate-commons-2.6.9.jar to C:\Users\Lu Sheng\.m2\repository\au\com\paymate\paymate-commons\2.6.9\paymate-commons-2.6.9.jar
[INFO] Installing F:\seprate\paymate-commons\pom.xml to C:\Users\Lu Sheng\.m2\repository\au\com\paymate\paymate-commons\2.6.9\paymate-commons-2.6.9.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.841 s
[INFO] Finished at: 2016-07-28T10:18:01+10:00
[INFO] Final Memory: 11M/155M
[INFO] ------------------------------------------------------------------------

之后我尝试构建取决于 paymate-commons 的 paymate-model

F:\seprate\paymate-model>mvn -o -DskipTests install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building paymate-model 2.6.9
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.944 s
[INFO] Finished at: 2016-07-28T10:21:22+10:00
[INFO] Final Memory: 7M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project paymate-model: Could not resolve dependencies for project au.com.paymate:paymate-model:jar:2.6.9: Failed to collect dependencies at au.com.paymate:paymate-commons:jar:2.6.9: Failed to read artifact descriptor for au.com.paymate:paymate-commons:jar:2.6.9: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact au.com.paymate:projects:pom:2.6.9 has not been downloaded from it before. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

我找不到伙伴 我使用 mvn -DskipTests install 或 mvn -DskipTests install 我不使用本地存储库 但是我可以在默认的本地存储库中找到 jar 文件。

C:\Users\Username\.m2\repository\au\com\paymate\paymate-commons\2.6.9

如何让电脑知道jar的位置并使用它?我需要在 pom.xml 上做一些设置吗?

【问题讨论】:

  • 您能否提供有关您正在使用的 pom.xml 的更多详细信息?在最后一条错误消息中显示“...工件 au.com.paymate:*projects*:pom:2.6.9 尚未下载...”这与您的工件不同以前安装过。
  • 我不明白这个:我找不到我使用 mvn -DskipTests installmvn -DskipTests install 我不知道使用本地存储库但我可以在默认本地存储库中找到 jar 文件。

标签: java maven repository pom.xml local


【解决方案1】:

您需要对setting.xml(不是pom.xml)进行一些设置! 找到您的 maven 目录,然后编辑 conf/setting.xml。 找到<localRepository>节点,写入你的.jar文件目录!

【讨论】:

    【解决方案2】:

    您可以尝试多种选择。

    1. 清理 au.com.paymate 文件夹并使用

      重新运行 payment-commons

      mvn -U 全新安装

      然后运行你的付款模式

    2. 使用absolute path提供依赖关系

    【讨论】:

      【解决方案3】:

      正如 Gonzalo Matheu 指出的那样,您缺少依赖项

      au.com.paymate:projects:pom:2.6.9
      

      按照名称,它应该是项目的一部分。也许您正在构建一个更大项目的一个模块?还是您忘记先创建另一个相关项目?

      无论如何,构建失败是因为au.com.paymate:projects:pom:2.6.9 不在您的本地存储库中,因此您必须从另一个存储库中获取它,或者您必须从相关项目中自己构建它。

      【讨论】:

        猜你喜欢
        • 2014-12-22
        • 1970-01-01
        • 2018-05-23
        • 2020-01-09
        • 2013-05-10
        • 2013-10-11
        • 1970-01-01
        • 2012-05-01
        相关资源
        最近更新 更多