views:

3094

answers:

4

Hi, I have an existing project that uses @Override on methods that override INTERFACE methods, and not superclass methods. I cannot alter this in code, but I would like eclipse to stop complaining about the annotation, as I can still build with maven.

How would I go about disabling this error?

Note: Due to project requirements, I need to compile for Java 1.5.

+16  A: 

This is only valid from Java 6 onward. It's an error in Java 5.

Make sure that your IDE projects are setup to use a Java 6 JRE, and that the "source compatibility" is set to 1.6 or greater. Open the Window > Preferences dialog, and browse to Java > Compiler. There you can set the "Compiler compliance level" to 1.6.


Update:

The error under Java 5 isn't just with Eclipse; using javac directly from the command line will give you the same error. It is not valid Java 5 source code.

However, you can specify the -target 1.5 option to JDK 6's javac, which will produce a Java 5 version class file from the Java 6 source code.

erickson
No, it won't. It will produce an error message "javac: source release 1.6 requires target release 1.6".
Michael Borgwardt
No, it won't. It will produce a compiled class file. It only gives that error if you specify the -source 1.6 option, which isn't necessary to make this work.
erickson
You know, since I build manually anyway, I can just leave the source level at 1.6. I could not get any sort of mixed configuration working, and this seems simplest.
Stefan Kendall
+1 saved me a headache
Tom Dignan
+4  A: 

You could change the compiler settings to accept Java 6 syntax but generate Java 5 output (as I remember). And set the "Generated class files compatibility" a bit lower if needed by your runtime. Update: I checked Eclipse, but it complains if I set source compatibility to 1.6 and class compatibility to 1.5. If 1.6 is not allowed I usually manually comment out the offending @Override annotations in the source (which doesn't help your case).

Update2: If you do only manual build, you could write a small program which copies the original project into a new one, strips @Override annotations from the java sources and you just hit Clean project in Eclipse.

kd304
Can you provide any specifics?
Stefan Kendall
It is on the same page as stated by erickson.
kd304
The project is several GB large. A simple "copy" isn't even practical. :/
Stefan Kendall
In this case, you'll need to ask for change permission. Or create a branch for the 1.5 compatible sources and manually fix the java files.
kd304
A: 

You can also try Retroweaver to create the Java5 version from Java6 classes.

A: 

Hi, try this out: Project->Properties->java compiler->

Enable project specific settings -yes Compiler compliance - 1.6 generated class files and source compatibility - 1.5

mitko