Compiler incompatibility?

Discussion in 'Java' started by Rhino, Apr 29, 2006.

  1. Rhino

    Rhino Guest

    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).

    --
    Rhino
    Rhino, Apr 29, 2006
    #1
    1. Advertising

  2. 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
    Jean-Francois Briere, Apr 29, 2006
    #2
    1. Advertising

  3. Rhino

    Rhino Guest

    "Jean-Francois Briere" <> wrote in message
    news:...
    > 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? ***
    >

    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, Apr 29, 2006
    #3
  4. Rhino

    Rhino Guest

    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
    Rhino, Apr 30, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward
    Replies:
    1
    Views:
    420
    Cowboy \(Gregory A. Beamer\)
    Jul 18, 2003
  2. hannibal
    Replies:
    1
    Views:
    344
  3. Attys Erebos

    DTD and CSS incompatibility?

    Attys Erebos, Oct 31, 2005, in forum: HTML
    Replies:
    4
    Views:
    488
    Jim Higson
    Nov 1, 2005
  4. Alan Sung
    Replies:
    3
    Views:
    884
    visage
    Aug 6, 2003
  5. Toon Knapen

    incompatibility of PGI compiler ?

    Toon Knapen, Mar 3, 2006, in forum: C++
    Replies:
    2
    Views:
    445
    Toon Knapen
    Mar 3, 2006
Loading...

Share This Page