hgbrgb
hgbrgb

Reputation: 13

Dependencies are not imported in project

I am using maven with eclipse I have struts and java ee dependencies in pom.xml

Here is my sample 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>

I have not copied my whole pom.xml

Question: All my jars in dependencies are downloaded and placed in my M2_REPO. But only junit jar is used by my project. Other jars(struts and javaee) are not used by my project. When i try to import the package, it fails.

My sample java program:

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;
    }
}

Here, it gives an error. It says "org.apache cannot be resolved".

Upvotes: 1

Views: 874

Answers (2)

lucrussell
lucrussell

Reputation: 5160

In addition to Sebastien's answer, check your Preferences > Classpath Variables, to ensure the M2_REPO variable is pointing to the correct path.

Upvotes: 1

Assuming you have m2e installed:

  • Right-click your project in Eclipse;
  • Click on Maven > Update Project...;
  • Make sure your project is ticked in the Update Maven Project window; click OK;

The project dependencies should then get updated, and your class should compile.

Another approach is to generate the Eclipse files from Maven:

mvn eclipse:eclipse

Upvotes: 0

Related Questions