Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Compiler incompatibility?

Thread view: 
Rhino - 29 Apr 2006 19:01 GMT
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).

Signature

Rhino

Jean-Francois Briere - 29 Apr 2006 19:59 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.