如何在maven中使用本地重新定位?

时间:2016-07-28 00:31:19

标签: java maven repository pom.xml local

我构建了常见项目并将其安装到本地存储库,然后我尝试使用相同的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模型

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安装或mvn -DskipTests安装我不使用本地存储 但我可以在默认的本地存储库中找到jar文件。

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

如何让电脑知道罐子的位置并使用它?我是否需要在pom.xml上进行一些设置?

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您可以尝试几种选择。

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

    重新运行付款公共文件

    mvn -U clean install

    然后运行您付款模式

  2. 使用absolute path

  3. 提供依赖关系

答案 2 :(得分:0)

正如Gonzalo Matheu指出的那样,你错过了依赖

au.com.paymate:projects:pom:2.6.9

在名称之后,它应该是项目的一部分。也许你只是在构建一个更大的项目的一个模块?或者您忘了先创建另一个相关项目?

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