Eclipse won't compile, bad class file, wrong version

后端 未结 9 1121
面向向阳花
面向向阳花 2021-01-18 01:46

I am trying to compile code checked out of SVN from another developer. Eclipse has been giving me a lot of trouble lately.

Here are my project-specific settings:

相关标签:
9条回答
  • 2021-01-18 02:01

    The class file version of 49.0 belongs to Java 1.5.x, whereas the one of 48.0 belongs to one of the Java 1.4.x version. The classfile structure had changed in 1.5 due to the introduction of several new features and changes made in the Java Language Specification.

    From the error, one can deduce that a Java 1.4 classfile was expected, whereas a Java 1.5 classfile was found. It appears that the compiler is a Java 1.4 compiler, so you should attempt to verify whether you're using the right version of the Java compiler and also the right JDK (i.e. JDK home).

    ADDENDUM

    Ant tends to look for the javac executable in the $JAVA_HOME/bin/javac . If the JAVA_HOME environment variable has been set incorrectly, say to a Java 1.4 home, then there is a likelihood of getting the described error even in Eclipse.

    ADDENDUM #2

    The addition of entries to the PATH environment variable could result in altering the search classpath behavior of Ant, possibly resulting in a different tools.jar being used for the purpose of compiling the sources. This might be due to the jvm.dll from the JRE 1.4.2 installation being used to run Eclipse (and hence Ant).

    0 讨论(0)
  • 2021-01-18 02:11

    First of all your project settings have nothing to do with your build script. Project settings tell you how Eclipse builds your project, not how your ant file will run.

    To find under which jvm ant runs, right-mouse click your build script in Eclipse and choose "Run as...". In the popup dialog navigate to jvm tab and check which jre is used to run your script.

    0 讨论(0)
  • 2021-01-18 02:11

    You seem to be running Ant with a version 1.5 java compiler but compiling against the class libraries (rt.jar) of a 1.6 installation. You should set up your build.xml so that it will consistently use both (the compiler and the class libraries) of the the same java version.

    0 讨论(0)
  • 2021-01-18 02:16

    You need to change the Java Version for ANT also because If you are using your Run Time Environment as JDK1.8 then Your ANT should be also point to same version or Ant should refer tools.jar file from JDK1.8/lib/tools.jar location. To fix this issue i your Eclipse Go to Window --> Preference --> Ant -->Runtime -->Global Entries . Here check and update tools.jar path with latest version as below.: C:\Program Files\Java\jdk1.8.0_60\lib\tools.jar

    Then run your build script issue will be resolved. :)

    0 讨论(0)
  • 2021-01-18 02:17

    bad class file: C:\Program Files\Java\jre1.6.0_07\lib\rt.jar(java/io/IOException.class)
    class file has wrong version 49.0, should be 48.0

    It is telling that the mentioned class file is been compiled using a compiler which generates class files of version 49.0, while ant expects it to be compiled using a compiler which generates class files of version 48.0. Since the class in question is part of the JRE, you need to update the classpath in your build.xml to include the JRE containing class files of version 48.0.

    0 讨论(0)
  • 2021-01-18 02:19

    The error message means that the compiler tool included in tool.jar your Ant is using is of older version than the class it attempts to compile. Message "[javac] class file has wrong version 50.0 should be 49.0" would mean that your class file needs jdk 6.0 but your tool.jar comes from jdk 5.0 distribution. To switch to correct tools.jar in eclipse open Window>Preferences>Ant>Runtime>Global Entries.

    0 讨论(0)
提交回复
热议问题