44

I'm having something quite peculiar here, my build is successful in maven when I type "mvn clean install" however once imported into Eclipse it's showing errors.

See for yourself:

mvn clean install

Eclipse

I guess exluding quartz from the `pom.xml solved the problem but I'd like to know why.


PS: Here is the pom.xml in case you want to see it:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.nantes.mpclient</groupId>
  <artifactId>MyClient</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MyClient</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.nantes.mp</groupId>
        <artifactId>MyEjb</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.jbossas</groupId>
        <artifactId>jboss-as-client</artifactId>
        <version>5.1.0.GA</version>
        <type>pom</type>
    </dependency>
  </dependencies>
</project>

###EDIT As you can see quartz is here: quartz

Heetola
  • 5,791
  • 7
  • 30
  • 45
  • Try `mvn dependency:tree` in the command line and check where the quartz dependency comes from. If it is included transitive can you find it in your local maven repository? – FrVaBe Jun 14 '12 at 13:11
  • the required version is inside my m2 :/ – Heetola Jun 14 '12 at 13:21
  • Oh you are right, I did not noticed :o sorry. anyway, I did the maven dance^^ but in the end the problem was coming from the fact that m2e was using it's embeded version of maven and not mine. – Heetola Jun 14 '12 at 14:00
  • I just noticed that you already found the reason and deleted my former comment about the different quartz versions. – FrVaBe Jun 14 '12 at 14:01
  • faced the same problem and https://stackoverflow.com/a/35932455/3724636 saved me – Ravinda Lakshan Dec 12 '19 at 10:28

21 Answers21

67

Updating maven project after importing it has fixed this issue for me:

Right click on the project --> Maven --> Update project.

arghtype
  • 4,376
  • 11
  • 45
  • 60
Hasnaa Ibraheem
  • 1,132
  • 1
  • 10
  • 18
16

Sometimes I get these types of issues as well.

Generally, what worked best for me with Eclipse & Maven:

  • Use the latest m2e Eclipse plugin
  • Use Maven 3
  • Make sure m2e uses the same Maven version as the one you're using on the command line (not the internal one)
  • Import projects as Maven projects to generate the Eclipse project files
Puce
  • 37,247
  • 13
  • 80
  • 152
  • 2
    I'm quite embarassed xD m2e was not using my version of maven. it was set to "embedded". I added the path to my maven installation and now it's working. – Heetola Jun 14 '12 at 13:34
10

The other upvoted answers did not work for me using these versions:

  • Eclipse Neon
  • Maven 3
  • m2e 1.7

This is what I had to do:

  1. Delete the Eclipse project from Eclipse interface (do not delete project contents on disk)
  2. Go to the project's root directory in a file explorer or terminal
  3. Delete these files: .classpath, .project, and .settings directory
  4. Back to Eclipse, File -> Import... -> Maven -> Existing Maven projects
Mike S
  • 11,329
  • 6
  • 41
  • 76
8

If you don't see any error in Eclipse project but it keeps showing the red icon on your project name. Try mvn eclipse:eclipse.

Then select all projects in Eclipse, Right click > Maven > Update projects

Hope it helps.

Vien Ng
  • 81
  • 1
  • 2
  • [**Apache Maven Eclipse Plugin (RETIRED) Note: This plugin is retired. It is no longer maintained.**](https://maven.apache.org/plugins/maven-eclipse-plugin/) – Gerold Broser Mar 05 '23 at 01:31
5

You should try mvn eclipse:eclipse

And then make sure the M2_REPO variable is point to your local repository.

plucury
  • 1,120
  • 1
  • 8
  • 16
  • I'm using m2e so I don't need to do eclipse:eclipse – Heetola Jun 14 '12 at 09:48
  • @Eildosa It seem you don't have quartz-1.5.2.jar.So add this dependency to your pom.xml, and try again. – plucury Jun 14 '12 at 09:51
  • If quartz is not in my pom.xml then eclipse is not suposed to look for it. And if it was a transitive dependancy it would download it. – Heetola Jun 14 '12 at 12:54
  • You saved my time. explored many options. But this was the ultimate one :) – HemChe Dec 17 '16 at 19:26
  • Don't do eclipse:eclipse, it creates bunch of file in the build path. – Mike May 04 '17 at 20:39
  • [**Apache Maven Eclipse Plugin (RETIRED) Note: This plugin is retired. It is no longer maintained.**](https://maven.apache.org/plugins/maven-eclipse-plugin/) – Gerold Broser Mar 05 '23 at 01:32
5

sometimes maven update nor all above works. so check which import statement gives you error, then go particular lib file which is usually in c:user/ur-PC-NAME/.m2 get into package delete that .jar file.

then in eclipse, right click on project > maven > update maven.

Shamanth Ramesh
  • 151
  • 2
  • 3
  • I found the same thing was happening to me. There was a .jar included as the scope "provided" and it was in my local repo but Eclipse wasn't detecting it. I did a Maven "update project" and it didn't work still. I was able to build the project from the command line maven. To resolve the issue, I did as you suggested, just deleted (or rename) the folder with the .jar in it in my maven local repo then update and build again and Eclipse picked it up. – atom88 Mar 19 '19 at 16:49
  • 1
    @atom88, Yes some time eclipse is not able to pick it up. Good it fixed your problem. – Shamanth Ramesh Aug 12 '20 at 12:19
  • @ShamanthRamesh, it worked, am using Eclipse 2020-09, please bear in mind to uncheck the `clean project` checkbox – adesst Sep 25 '20 at 06:25
4

Sometimes the m2e "maintained" eclipse project is out-of-sync with the actual project in POM (There are lots of reason for that). Assume you have using m2e 0.8 or later, right click on the project, under Maven, there are two entries that are usually useful. They are Update Dependencies and Update Project Configuration

Have a try on them, wait a while after u clicked that for eclipse to update the project and build. Normally it solves similar problems.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • didn't worked :/ I think I'm just going to exclude it (must be a transitive dependancy from jboss as client) because I tried everything... – Heetola Jun 14 '12 at 12:55
3

That often happens when the m2eclipse hasn't updated the build path to correspond to what a modified POM file says. There's an entry in the Maven context menu to update the Configuration.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
2

In my case,

  1. I just deleted project from Eclipse (not ticked checkbox to delete from project location).

  2. Opened project as "Existing Maven Project" again.

and it solved my issue.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
1

I found that my project was using a project specific Java Compiler setting set to Java 1.5. Furthermore, the project facets were still referencing Java 1.5 when Maven, m2e, Eclipse general Java Compiler settings were all set to Java 1.8.

espressoT
  • 11
  • 1
  • This is normally adjusted by "Update Project from Maven POM", but not always. It is good to see the JRE used in the library path to get alerted. – eckes Nov 19 '14 at 22:30
1

In my case there were also problems with Java build path like the following: "Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment." Fixing this resolved compilation errors.

sergeyan
  • 1,173
  • 1
  • 14
  • 28
0

You've a library (quartz-1.5.2.jar) that's reference to your m2 local repository which doesn't exist if you just remove the quartz from your build path and update your dependencies internally(in eclipse) that would solve the problem

mb2015
  • 168
  • 4
0

Try to use different/older version of JRE. In my case switching back to JRE7 from JRE8 eliminated the problem.

Yan
  • 1
0

Delete and Re-Import the project in eclipse (without deleting files of course). Unlike other answers I have not looked into why this happens but it works. poof - compilations errors be-gone

Rob McFeely
  • 2,823
  • 8
  • 33
  • 50
0

It may help: After upgrading eclipse or changing it or something like, old eclipse specific files (.classpath, .project, and .settings) may not be compatible to the new version of eclipse. So you may have to re generate this eclipse specific files using Maven. So try this in your eclipse project root

mvn eclipse:eclipse
Youness HARDI
  • 402
  • 1
  • 3
  • 13
  • [**Apache Maven Eclipse Plugin (RETIRED) Note: This plugin is retired. It is no longer maintained.**](https://maven.apache.org/plugins/maven-eclipse-plugin/) – Gerold Broser Mar 05 '23 at 01:34
0

In my case, eclipse starts to show all errors after I changed some versions of dependencies in pom.xml, however the command line mvn clean install build successfully

  1. I deleted folders of the dependencies I changed manually from the .m2 repositories (in my case everything under org.apache.beam), because I also has corrupted dependency issues.
  2. mvn clean build the project, this downloaded the dependencies again
  3. right click project: maven -> update project
  4. delete the project from eclipse (but not from disk) and reimport (this actually left me with 1 error still, then i delete and reimported again)
Angia
  • 177
  • 2
  • 4
0

Go to Eclipse> Project (Menu) > Clean... > Select project to clean

This also removes invalid errors from Eclipse.

Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
0

For me Right click on the project --> Maven --> Update project with the "Force Update of Snapshots/Releases" checkmarked worked.

0

Some times, eclipse's validation causing these errors. You can disable them by going to Menu>window>preferences>validation and uncheck suspend all validators or disable them one by one for builds. E.G, every time You build the project eclipse does not validate your files and does not show up those errors.

hamidreza75
  • 567
  • 6
  • 15
0

This worked for me

  1. Delete the Eclipse project from Eclipse interface (do not delete project contents on disk)
  2. Go to the project's root directory in a file explorer or terminal
  3. Delete these files: .classpath, .project, and .settings directory
  4. Back to Eclipse, File -> Import... -> Maven -> Existing Maven projects
0

Got the same problem, I deleted the project from my workspace (not on disk), opened the project folder and deleted the files .project, .classpath and the folder named .settings.
Now goto eclipse again, import the same project again and viola my error is gone!

Suresh
  • 1,491
  • 2
  • 22
  • 27