Maven pom.xml本地依赖未解析

时间:2016-03-15 05:12:41

标签: java eclipse web-services maven

使用eclipse mavenjava 1.7我设计了两个名为webservice.staff.backend webservice.webuser.backend的后端。

现在还有一个webservice由我们的高级团队成员编写,这是我与git共享的另一个项目模块。

  

pom.xml的新项目中,有两个本地项目依赖已添加为关注。

    <dependency>
        <groupId>webservice.staff.backend</groupId>
        <artifactId>webservice.staff.backend</artifactId>
        <version>1.0.0</version>
        <classifier>classes</classifier>
        <type>jar</type>   //used jar but webservices packaging as a war
    </dependency>
    <dependency>
        <groupId>webservice.webuser.backend</groupId>
        <artifactId>webservice.webuser.backend</artifactId>
        <version>1.0.0</version>
        <classifier>classes</classifier>
        <type>jar</type> // used jar but webservices packaging as a war
    </dependency>

但是当我尝试执行 Maven clean install时,这些依赖关系无法解决。我在之前的webservice项目中找到的内容包装为WAR,但此处用作jar

  

以下是pom.xml中的早期项目打包类型。

<groupId>webservice.staff.backend</groupId>
    <artifactId>webservice.staff.backend</artifactId>
    <packaging>war</packaging> //packaged as war but used as jar??

<groupId>webservice.webuser.backend</groupId>
    <artifactId>webservice.webuser.backend</artifactId>
    <packaging>war</packaging>  //packaged as war but used as jar in

    /*I Have also Changed packaging as a jar and then clean Install 
      and try to build the New Project but error still the same. */

错误StackTrace

[ERROR] Failed to execute goal on project webservice.credit.backend: Could not resolve dependencies for project webservice.credit.backend:webservice.credit.backend:war:2.0.0: The following artifacts could not be resolved: webservice.staff.webservice.staff.backend:jar:classes:1.0.0, webservice.webuser.backend:webservice.webuser.backend:jar:classes:1.0.0: Failure to find webservice.staff.backend:webservice.staff.backend:jar:classes:1.0.0 in http://download.java.net/maven/2/ was cached in the local repository, resolution will not be reattempted until the update interval of Java.Net has elapsed or updates are forced -> [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.
  

注意: - 我在stackOverflow就这方面尝试了很多方法和答案,但没有人给我正确的解决方法。

请帮助任何人解决此问题。谢谢。

2 个答案:

答案 0 :(得分:0)

最后 !!!
 得到了解决方案。

clean期间我需要做什么install使用param添加额外mvn以导出类文件。参数==&gt; -Dattach.and.archive.classes=true命令mvn

mvn clean install -Dattach.and.archive.classes=true //added one extra param
   // -Dattach.and.archive.classes=true solved my dependency Problem.
  

注意: - 如果您在pom.xml项目打包中定义为war,并希望jar作为您本地maven存储库中的依赖项。只需将这个额外的选项与-Dattach.and.archive.classes=true mvn放在一起。

答案 1 :(得分:0)

删除<classifier>classes</classifier>

<dependency>
    <groupId>webservice.staff.backend</groupId>
    <artifactId>webservice.staff.backend</artifactId>
    <version>1.0.0</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>webservice.webuser.backend</groupId>
    <artifactId>webservice.webuser.backend</artifactId>
    <version>1.0.0</version>
    <type>jar</type>
</dependency>

pom对于两个项目都是相同的,除了包装将是jar:

<groupId>webservice.staff.backend</groupId>
<artifactId>webservice.staff.backend</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>

<groupId>webservice.webuser.backend</groupId>
<artifactId>webservice.webuser.backend</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>

确保您的settings.xml如下所示:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>${user.home}/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  ------
</settings>

我上传了示例here