Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong maven compilation error (works in eclipse)

Tags:

java

maven

I'm getting a compilation error when I compile using maven but works in eclipse. Both are using the same JDK:

java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)

mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/jdk1.6.0_35/jre
Default locale: es_ES, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-29-generic", arch: "amd64", family: "unix"

This is the error:

[ERROR] /blablabla.../myClass.java:    [78,107] inconvertible types
[ERROR] found   : java.util.Collection<java.lang.Object>
[ERROR] required: java.util.Collection<? extends org.springframework.integration.store.MessageGroup>
[ERROR] -> [Help 1]

And this is the code (no compilation error in eclipse):

Collection<? extends MessageGroup> collection = (Collection<? extends MessageGroup>) this.groupMap.values();

I know that this is a pretty recursive issue, I've found a few posts asking the same, but seems that nobody has a standar fix. Some people say that works with different JDK version. I have tested with 1.6.0_30, 1.6.0_31, 1.6.0_32 and 1.6.0_35 and all fail.

Any idea?

Thanks

like image 802
Curro Avatar asked Aug 30 '12 17:08

Curro


People also ask

Why does Maven build failure in Eclipse?

The error message indicates that Maven is unable to find the Java compiler, which comes only with a JDK and not with a JRE.

How do I fix POM xml error in Eclipse?

Additionally,right click on the pom. xml file in the 'project explorer' > click on 'validate'. This should remove the red-error mark on file, if there are no problems in the XML configuration.


1 Answers

I suspect eclipse isn't using the JDK you think it is. Try using type erasure.

Collection<? extends MessageGroup> collection = 
        (Collection<? extends MessageGroup>)
                (Collection) this.groupMap.values();
like image 195
Peter Lawrey Avatar answered Sep 24 '22 19:09

Peter Lawrey