Compiler incompatibility?

R

Rhino

I am trying to compile a Java class, Foo, that has a dependency on another
Java class, Bar. I'm getting this message from the compile, which is taking
place in an Ant script:

[javac] Compiling 1 source file to
E:\eclipse\3.0.1\eclipse\workspace\RDS\bin

[javac]
E:\eclipse\3.0.1\eclipse\workspace\RDS\src\com\xyz\java\TextUDFs.java:58:
cannot access com.xyz.java.Bar

[javac] bad class file:
E:\eclipse\3.0.1\eclipse\workspace\RDS\bin\com\xyz\java\Bar.class

[javac] class file has wrong version 49.0, should be 48.0

[javac] Please remove or make sure it appears in the correct subdirectory of
the classpath.

[javac] private static Bar bar = null;

[javac] ^

[javac] 1 error


I'm not quite clear on what is going on here. Can anyone enlighten me?

The message makes it sound like the code for class Bar was generated with a
later compiler, e.g. 1.5.0, than the code for class Foo, e.g. 1.4.0, but I
don't think that is the case.

What do I need to do to make Foo and Bar play nicely together?

I'm using Ant 1.6.2 within Eclipse 3.1.1 on Windows XP (SP2).
 
J

Jean-Francois Briere

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
 
R

Rhino

Jean-Francois Briere said:
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:
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? ***
Yes, I have a tools.jar, specifically D:\Java\jdk1.5.0_06\lib\tools.jar.
2- In Eclipse:
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".
 
R

Rhino

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top