wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes ANT doesn't understand Java 5 @Override Annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ANT doesn Watch "ANT doesn New topic
Author

ANT doesn't understand Java 5 @Override Annotation

Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Hi,
I've come across a strange issue. I'm using Eclipse IDE with Java SE 6. When I correctly override a method from a parent class/interface and use @Override annotation, Eclipse doesn't complaint (as expected because it's a valid override). However, when I compile with ANT (version 1.7) I get the following compilation error:




This is strange. Any help shall be highly appreciated.

Lisa
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Ant isn't doing the compiling, whatever compiler you have configured is.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Bear wrote:
Ant isn't doing the compiling, whatever compiler you have configured is.


I've configured compiling as shown below:
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
From the original compile error, it looks like it does understand @Override Annotation but disagrees that it is valid. Perhaps show us more code (like at least the two method signatures)
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
If there was some issue with the method override, the Eclipse compiler would have reported that. Still, I'm sharing the code.

POJI



POJO




Ant


Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Looks like it is a difference between java 5 & 6.

[EDIT] OK, that looks like one of my typical terse replies. I should add a little more info...

I use eclipse. I set the JRE to 1.6 and set the compiler compliance level to 6.0. Eclipse puts in the @Override in the class that implements the interface if I have eclipse put the method in (create the class, but no method and it complains that the class needs to implement something and I have it "add unimplemented methods"). If I change the compliance level to 5.0 it then complains about @Override. When I have eclipse add the method (5.0 still) it doesn't add the @Override.

(Maybe it was better without the added explanation?)
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Carol wrote:
Looks like it is a difference between java 5 & 6.


I tried doing the following changes and failed:



And,


Carol, What needs to be done to get off this issue?


In anticipation.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I haven't tried it out as I never use target/source with javac. Looks like 1.6 should work,possibly 6. Maybe I'll go try that.

I'd try running ant verbosely (ant -v) to see what version it is trying to use. Perhaps it is 5 and can't do 6.


[EDIT] Oh by the way, welcome to JavaRanch!!!
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
Hi All,
This is what I did to get out of the mess and make Ant Happy.

Ant and Eclipse are happy when:
Java compiler's compliance is set to Java 6
Ant Global Entries point to Java 6 tools.jar

Ant and Eclipse are unhappy when:
Java compiler's compliance is set to Java 6
Ant Global Entries point to Java 5 tools.jar


Eclipse is unhappy when

Java compiler's compliance is set to Java 6 (this is strange even when it's a valid override). Can somebody explain this weird behavior.




Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Well, as you've seen, it's best when you keep to the same Java environment all the way through.

Your message "method does not override a method from its superclass " almost certainly comes from classloading issues. Part of Java's security model is that just because 2 classes have the exact same name and signatures doesn't mean that Java will consider them to be the same class. It's also important that they be on the same classpath branch.

As for Eclipse's problems, the first thing you need to do is ensure that you've installed the desired JDK into Eclipse and that the project in question is going to refer to it, either because it's the default workspace JRE or by an explict override. The Java Version Compliance setting in the Build Properties dialog is primarily for Eclipse to use as guidance on how to control editing (for example, flagging "enum", and use of annotations/generics/iterators), but the underlying selected JDK determines how classes get resolved.


Customer surveys are for companies who didn't pay proper attention to begin with.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
The difference between Java 1.5 and 1.6 is:

in 1.5, @Override is accepted only in the case of extending a class. If you are implementing a method in an interface, then you cannot use this annotation.

In 1.6, @Override is acceptable when implementing a method from an interface.

If you need Ant to accept the 1.6 usage, then set the compiler source compliance to "1.6" in your build.xml: <javac source="1.6"..... />

Geoffrey

Sun Certified Programmer for the Java 2 Platform
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Interestingly, this change from Java 5 to Java 6 apparently wasn't documented anywhere: http://blogs.sun.com/ahe/entry/override_snafu thus taking many people (including myself :-) by surprise.


Ping & DNS - updated with new look and Ping home screen widget
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

Ulf Dittmer wrote:Interestingly, this change from Java 5 to Java 6 apparently wasn't documented anywhere: http://blogs.sun.com/ahe/entry/override_snafu thus taking many people (including myself :-) by surprise.

And a Java 6 compiler in Java 5 mode doesn't tell you about it. Which means Ulf has caught me using @Override in a way that doesn't work on a real Java 5 compiler a number of times


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Aneel Sahoo
Greenhorn

Joined: Mar 16, 2009
Posts: 2
Anil Sahu wrote:Thanks everyone for posting the solution. It all worked fine when I pointed Java to 6 instead of 5.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ANT doesn't understand Java 5 @Override Annotation
 
Similar Threads
I just destroyed Polymorphism
Proper use of @Override?
K &B Mock exam Question doubt
What's the difference between hashcode() and equals() methods?
IllegalStateException in forward