9

I installed m2eclipse to build a java project in Eclipse.

I imported the project as follows:

Import->
Maven->
Existing Maven Projects->
Import Maven Projects->
- Select root directory
- Select pom file
- Click Finish

To be sure m2eclipse was actually building the project, I deleted the target directory and made sure it was re-created by m2eclipse and it was. But unlike with the command-line version of maven which built everything perfectly, m2eclipse leaves a large number of build errors in the source code.

Is it possible that I did not configure m2eclipse properly? How would I check this?

This is a github link to the project I'm trying to build. I'm getting the @Override build errors at this line. It says "The method createNewToken must override a superclass method".

Chris Collins
  • 3,440
  • 5
  • 27
  • 24
  • Post some example of errors please (by the way m2eclipse uses an embedded version of maven 3 by default, i.e. very likely not the same version than you on the command line). But post some errors, we're not mediums :) – Pascal Thivent Aug 21 '10 at 19:04
  • You can activate debug output in the maven preferences to see in detail what's going on. I'd suggest to also try just refreshing the dependencies (right-click on project->maven->update dependencies iirc), maybe that helps. Also how are you building the project inside eclipse? Do you invoke a maven goal/phase explicitly? If so post the run configuration. – Raoul Duke Aug 21 '10 at 19:06
  • Actually, as far as I can tell, all of the errors say "Remove @Override annotation" -> "The method x must override a superclass method". I tried (right-click on project->maven->update dependencies) but it didn't help. As for the question, how am I building the project, well I just imported the project using the pom file and assumed that it would build automatically. In fact, it says: "Maven Builder: AUTO_BUILD " on the eclipse console. – Chris Collins Aug 21 '10 at 19:22
  • @Raoul: I enabled maven debug output but no information about build problems there. – Chris Collins Aug 21 '10 at 19:27
  • Please show a class allowing to reproduce the problem (and its superclass/interface). – Pascal Thivent Aug 21 '10 at 19:29
  • This is the project I'm trying to build: http://github.com/tleese22/google-app-engine-jappstart . I'm getting the @Override build errors at this line: http://github.com/tleese22/google-app-engine-jappstart/blob/master/src/main/java/com/jappstart/service/auth/PersistentTokenRepositoryImpl.java#L100 – Chris Collins Aug 21 '10 at 19:41
  • @Chris - I checked in a new pom.xml with the source level set to 1.6. – Taylor Leese Aug 23 '10 at 01:28

3 Answers3

13

Update: The problem is the same as the one described in ‘Must Override a Superclass Method’ Errors after importing a project into Eclipse and here is what the accepted answer says:

Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method).

Changing the compiler level to Java 1.6 would make the problem go away. To do so, modify the compiler plugin configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

And update the project configuration (right-click on the project then Maven V Update Project Configuration) does solve the problem under Eclipse.

Or stick with 1.5 but remove the problematic @Override annotations.

I don't know how Taylor got things working with a Java 1.5 compiler level. And my guess is that the project wouldn't build on the command line with a JDK 5.


But unlike with the command-line version of maven which built everything perfectly, m2eclipse leaves a large number of build errors in the source code.

Hard to say what is happening exactly without seeing those "errors" (are them really errors?). Please provide some traces.

Is it possible that I did not configure m2eclipse properly? How would I check this?

One difference is that m2eclipse uses by default a embedded version of Maven 3 which is probably not the same version that you use on the command line. You can change that through Window V Preferences V Maven V Installation (and add your own installation):

alt text

But while I would recommend to use the same version under Eclipse than on the command line, this is very likely not the root cause of the problem, Maven 2 builds should run on Maven 3 without problems.

Community
  • 1
  • 1
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • I tried switching to the maven2 installation but, as you suspected, it had no effect on the build errors. But thanks for the screenshot. I didn't know it was so easy to switch the installation from the default. – Chris Collins Aug 21 '10 at 19:48
  • It seems Raoul is experiencing the exact same problems with this code. I assumed it was just something I was doing. – Chris Collins Aug 21 '10 at 20:10
  • @Raoul Please double check your claims because it does work for me and I'm 200% sure of what I'm saying. – Pascal Thivent Aug 21 '10 at 22:20
  • It works perfectly now. Some of the "Content Assist" problems I was having earlier have also been eliminated. – Chris Collins Aug 21 '10 at 22:26
1

I checked out the code. I have exactly the same problem. The code seems to be just broken.

Edit: It definitely is. Look at the class com.jappstart.service.auth.UserDetailsServiceImpl. It wants to override the method public final UserDetails loadUserByUsername(final String username) but this method doesn't exist in the interface the class implements and is has no superclass.

Edit: Ok, that doesn't explain why it builds with maven standalone. This also works for me. Very strange. It seems that there is something going on with the build that doesn't work with m2eclipse.

Edit: I'm pretty sure the code works because the bytecode is modified by the datanucleus plugin. When I run the project as maven build (right-click->Run->maven package) it sucessfully creates the war with m2eclipse. So my guess is that the problem is with the m2eclipse Maven Builder.

Raoul Duke
  • 4,241
  • 2
  • 23
  • 18
  • Thanks for checking out the code. I'm glad you were able to verify that it works with maven standalone but not with m2eclipse. But, based on Pascal's advice, I have set m2eclipse to use my standalone maven installation. So this makes it all the more mysterious why there would be a difference. – Chris Collins Aug 21 '10 at 20:06
  • I suspect it has to do with the datanucleus plugin. This plugin appears to do some bytecode manipulation which could explain that the "broken" code can be compiled. I don't understand however why it doesn't seem work with m2eclipse. – Raoul Duke Aug 21 '10 at 20:11
1

The override errors will appear if eclipse is configured to use java 1.5 instead of 1.6. Check the project properties.

Taylor Leese
  • 51,004
  • 28
  • 112
  • 141
  • @Chris Did you read my answer Chris? I provided the *right* solution (configuring the `maven-compiler-plugin` for 1.6 **IN** the pom.xml). This is the way to go, m2eclipse derives the settings from the pom.xml. And this what Taylor should do, one shouldn't have to change the IDE settings after import. – Pascal Thivent Aug 21 '10 at 22:18
  • 1
    Sure, I will change the POM to list 1.6 when I get a chance (probably tomorrow evening). My Eclipse project settings were at 1.6 so I never noticed this. – Taylor Leese Aug 21 '10 at 22:28