【问题标题】:Dependencies are not imported in project项目中未导入依赖项
【发布时间】:2013-03-31 16:30:35
【问题描述】:

我在 Eclipse 中使用 Maven 我在 pom.xml 中有 struts 和 java ee 依赖项

这是我的示例 pom.xml

  <dependencies>
    <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>3.8.1</version>
               <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>

    </dependency>

    <dependency>
        <groupId>struts</groupId>
        <artifactId>struts</artifactId>
        <version>1.2.9</version>
    </dependency>
  </dependencies>

我没有复制我的整个 pom.xml

问题:我所有依赖项中的 jar 都已下载并放置在我的 M2_REPO 中。但是我的项目只使用了junit jar。我的项目没有使用其他 jars(struts 和 javaee)。 当我尝试导入包时,它失败了。

我的示例 java 程序:

package org.xinotes;

import org.apache.struts.action.ActionForm;

public class HelloForm extends ActionForm 
{
    private String name;

    public String getName() 
    {
    return this.name;
    }

    public void setName(String name) 
    {
    this.name = name;
    }
}

在这里,它给出了一个错误。它说“org.apache 无法解析”。

【问题讨论】:

    标签: eclipse maven


    【解决方案1】:

    除了 Sebastien 的回答,检查您的 Preferences > Classpath Variables,以确保 M2_REPO 变量指向正确的路径。

    【讨论】:

      【解决方案2】:

      假设您已安装 m2e:

      • 在 Eclipse 中右键单击您的项目;
      • 点击Maven > 更新项目...;
      • 确保在更新 Maven 项目窗口中勾选了您的项目;点击确定;

      然后项目依赖项应该得到更新,你的类应该编译。

      另一种方法是从 Maven 生成 Eclipse 文件:

      mvn eclipse:eclipse
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-17
        • 2016-09-14
        • 1970-01-01
        • 2021-04-05
        • 1970-01-01
        • 2021-01-27
        • 1970-01-01
        相关资源
        最近更新 更多