The ANT javac task uses the JDK compiler. You must use a 1.4 version of
the JDK I guess.
The Eclipse project in the other hand uses the Eclipse compiler, which
must be set to 5.0 compliance level I guess.
Every time you save a .java file in your project it automatically
rebuild with the Eclipse compiler.
But when you start the execution of the ANT script in your project or
from the command line you use the JDK compiler and it can lead to
dependent .class files mismatch.
Two questions to be answered first:
1- In Eclipse:
>From the menu: 'Window' / 'Preferences...'
In the window, left side: expand 'Ant' then click on 'Runtime'
On the right side: expand 'Global Entries'
*** What do you see? Do you have a tools.jar in it? Does it come from a
JDK 1.4? Else? ***
2- In Eclipse:
>From the Package Explorer window: right-click on your project then
select 'Properties'
In the window, left side: click on 'Java Compiler'
*** On the right side, what is the compiler compliance level? ***
Regards
Rhino - 29 Apr 2006 23:13 GMT
> The ANT javac task uses the JDK compiler. You must use a 1.4 version of
> the JDK I guess.
[quoted text clipped - 13 lines]
> *** What do you see? Do you have a tools.jar in it? Does it come from a
> JDK 1.4? Else? ***
Yes, I have a tools.jar, specifically D:\Java\jdk1.5.0_06\lib\tools.jar.
> 2- In Eclipse:
>>From the Package Explorer window: right-click on your project then
> select 'Properties'
> In the window, left side: click on 'Java Compiler'
> *** On the right side, what is the compiler compliance level? ***
All of the JDK Compliance section is greyed out ("Enable project specific
settings" is NOT checked). However, but the compiler compliance level is
clearly 5.0. By the same token, in Windows/Preferences/Java/Compiler,
Compiler Compliance level is 5.0 and "use default compliance settings" is
checked.
Also, the value of the compiler parameter in my Ant javac task is "modern".
--
Rhino
Rhino - 30 Apr 2006 00:12 GMT
Just to update anyone following this thread, I have solved the problem,
although I'm not quite sure why this solution worked.
First, I tired making a trivial change to the source of Bar, the class I was
depending on, to force Eclipse to recompile it. The recompile worked and the
date on the .class file was updated but the compile of Foo failed on the
same error.
Then, I tried deleting the .class file for Bar just to see what would
happen. I expected to have to recompile Bar to create the .class file but I
tried the compile of Foo, just for laughs, with the Bar.class file no longer
in existence. Much to my surprise, the compile of Foo worked fine!
Also, a new copy of Bar.class wound up in the directory where it was
supposed to be, even though I had deleted the old Bar.class and had NOT
recompiled the source. Or maybe I should say I didn't force it to recompile
in Eclipse! My Javac task in Ant somehow figured out that Bar.java needed to
be recompiled and did it for me and, since both Bar and Foo were compiled by
the Ant javac compiler this time, they were both compatible and the compile
of Foo worked.
--
Rhino