I have few Eclipse Java Projects and I converted them into Maven. All the projects are showing errors where interface methods are overwritten. But I when I run "mvn clean" it does show as build success. Also when I remove the maven nature, the projects compile without an issue. Why is this happening? Please advice.
-
try clean and refresh. – nano_nano Dec 11 '15 at 10:56
-
I tried that. Doesn't work. Cleaned from maven as well as eclipse. Nothing works. – AnOldSoul Dec 11 '15 at 10:57
-
Which Java Version do you use in eclipse? – Jens Dec 11 '15 at 10:59
-
I am using java 1.8. Maven is 3.3 – AnOldSoul Dec 11 '15 at 10:59
-
Does you eclipse show all the correct deps under Maven Dependencies? – Yogesh_D Dec 11 '15 at 11:08
-
yes. Else it would have thrown errors saying it can't find the interface. This one says the interface doesn't contain those methods I have overwritten. – AnOldSoul Dec 11 '15 at 11:22
-
have you tried `mvn clean install` from command line? – Dominik Reinert Dec 11 '15 at 11:22
1 Answers
This is most likely due to your pom missing a specification of which Java version you are targeting; JDK versions prior to 1.6 didn't allow the @Override
annotation on methods that implemented interface methods. You should always specify he Java version so Maven doesn't have to guess what you intend. For example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
When you tell maven to configure your Eclipse Project or import it via m2e, it looks for that configuration to apply to corresponding configuration in Eclipse. If the version is absent, it uses whatever is the default for your workspace, which can vary between workspaces. You probably are running into that, where it's guessed wrong.
You can manually fix the project config in Eclipse, too; see https://stackoverflow.com/a/1678170/639520
But fixing the pom is a good idea anyway and then refreshing/updating the Eclipse config should pick it up.