tags:

views:

57

answers:

4

How come Eclipse compiles my project (automatically) without errors, but when I run Ant build.xml -> compile target, the build fails with compile error:

<MyClass> is not abstract and does not override abstract method <someMethod>

I understand this error message, but it seems not to be true, because 1) Eclipse shows no errors 2) Deploying this project to server succeeds and the class works as it should work.

So how is this problem even possible?

+2  A: 

Are you using some special extensions to Eclipse, like Lombok (could be the extension generate something for you)? Are you using some special framework (could be the framework generate some class for you)?

What you also need to understand is Eclipse and Ant using different compiler. Eclipse has its own compiler which behave differently with the Sun JDK, or with certain version of Sun JDK. One example of such behavior can be read here. But before I jump to that conclusion, I will inspect all configurations I have on my Eclipse.

nanda
A: 

Because there are minor differences in the Eclipse compiler. I found a bug once, too, where the Javac threw an (IMHO stupid) error, while the Eclipse compiler was able to compile it like expected.

FYI: Eclipse uses a different compiler (its own) because it needs one optimized for incremental builds while you type.

Create a test case that shows that the differences are real, and send it to the eclipse team. They will adjust the behaviour of their compiler. However, I can't believe that such a major bug like an unimplemented method is really in the Eclipse compiler. I therefore assume you find the bug in your setup while creating a testcase for that.

Daniel
+1  A: 

It's also possible that your Ant build is just not set up the same as your Eclipse build. Different source folders, different JARs, etc. For example, perhaps your Eclipse build references an old version of a third-party JAR, and your Ant build references a new version where a new abstract method was added to a class you're inheriting from.

dty
A: 

Thank you all for your quick answers. It has been very helpful to understand that Eclipse uses different compiler, that explained a lot.

As for my problem - I assumed that Java compiler is right and that the build actually had errors. On closer examination, it occured to be the incompatibility of an older version of Apache Commons DBCP with Java 1.6. I was sure I was using the latest one and consulted wrong documentation version, which stated that the required methods were implemented.

Now as for Eclipse. The bug is actually tricky. I managed to write a test case showing this bug. I use Java 1.6 and Eclipse Helios for Java EE. I created a Java project in Eclipse and added

com.springsource.org.apache.commons.pool-1.5.3.jar com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar

to the classpath (downloaded these JARs from SpringSource repository). As you see, Apache Commons DBCP is an old one. Java 1.6 requres version 1.4+.

In my test project I extend org.apache.commons.dbcp.BasicDataSource and additionally said it should implement javax.sql.DataSource. Like this:

import org.apache.commons.dbcp.BasicDataSource;
import javax.sql.DataSource;

public class MyDataSource extends BasicDataSource implements DataSource {

}

The tricky part here is that BasicDataSource implements DataSource interface. But in version 1.6 this interface got extended it, so the new methods are not implemented. Adding "implements DataSource" again explicitly should cause and error, which Java compiler successfully reports. But Eclipse compiles this code without any warning and it even runs.

So that was the problem. Seems like a bug in Eclipse to me.

Infeligo
Great that you've solve the problem. Please check one more time the classpath in your Eclipse project properties if you use Java 1.6.
nanda
There's not much to check. I have only Java 1.6 installed and add those JARs via project properties window. What do you think about it, is it Eclipse's bug?
Infeligo
OK, so I filled bug report with even simpler test case: https://bugs.eclipse.org/bugs/show_bug.cgi?id=327881
Infeligo