Eclipse不会编译,坏类文件,错误的版本 [英] Eclipse won't compile, bad class file, wrong version

查看:168
本文介绍了Eclipse不会编译,坏类文件,错误的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从另一个开发人员编译SVN签出的代码。 Eclipse最近一直给我很多麻烦。

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:

这是我的ant文件的编译部分:

This is what the compile section of my ant file:

<target name="compile" depends="build-common, init" description="Compile files. ">
    <javac srcdir="${src_dir}" destdir="${build_dir}" debug="true" >
        <classpath path="${tomcat_home}/lib/servlet-api.jar;" />
    </javac>
</target>

当我编译(使用Ant)我收到一条错误消息:

When I compile ( using Ant ) I get an error message:

compile:
    [javac] Compiling 3 source files to H:\MYCOMPANY\portlets\build
    [javac] H:\MYCOMPANY\portlets\src\com\mycompany\portlets\CourseList.java:3: cannot access java.io.IOException
    [javac] bad class file: C:\Program Files\Java\jre1.6.0_07\lib\rt.jar(java/io/IOException.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] import java.io.IOException;
    [javac]                ^
    [javac] 1 error

这个错误是什么意思?

What does this error mean?

推荐答案

49.0的类文件版本属于Java 1.5.x,而48.0中的一个属于Java 1.4 .x版本。由于引入了Java语言规范中的几个新功能和更改,类文件结构在1.5中已更改。

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.

从错误中可以推断出Java 1.4 classfile是预期的,而Java 1.5类文件被发现。看来编译器是一个Java 1.4编译器,所以你应该尝试验证你是否使用正确版本的Java编译器,还有正确的JDK(即JDK home)。

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倾向于在$ JAVA_HOME / bin / javac中查找javac可执行文件。如果JAVA_HOME环境变量设置不正确,对Java 1.4家庭来说,即使在Eclipse中也有可能得到描述的错误。

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.

添加#2

添加条目到PATH环境变量可能会导致改变Ant的搜索类路径行为,可能导致在另一个tools.jar中用于编译源的目的。这可能是由于来自JRE 1.4.2安装的jvm.dll用于运行Eclipse(因此是Ant)。

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

这篇关于Eclipse不会编译,坏类文件,错误的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆