错误的类文件使ant构建失败 [英] Bad class file failed the ant build

查看:163
本文介绍了错误的类文件使ant构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是将jdk1.6更改为1.8,并且在构建新的ant构建时,它会给出以下错误消息:

I just changed jdk from 1.6 to 1.8 and when making an new ant build, it gives such error messages:

[javac] /usr/workspace/test/src/JsonString.java:7: cannot access java.lang.Object
[javac] bad class file: java/lang/Object.class(java/lang:Object.class)
[javac] class file has wrong version 52.0, should be 50.0
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
[javac] public class JsonString {
[javac] 

这很奇怪. Object类应该在java1.8中,怎么会不好呢?有人知道如何解决这个问题吗?

This is weird. the Object class should be in java1.8, how could it be bad? Do anyone know how to solve this?

推荐答案

首先检查javac任务是否未使用默认编译器以外的特定编译器.如),则会发生这种情况. .html"rel =" nofollow>任务文档:

First check that the javac task is not using a specific compiler other than the default one. This can occur if you're setting the executable attribute to fork a specific compiler (along with fork="yes"), as mentioned in the task documentation:

可执行

要在fork ="yes"情况下使用的javac可执行文件的完整路径.默认为当前正在运行Ant的Java版本的编译器.如果fork ="no"则忽略. 从Ant 1.6开始,使用jikes,jvc,gcj或sj时,此属性还可用于指定可执行文件的路径.

Complete path to the javac executable to use in case of fork="yes". Defaults to the compiler of the Java version that is currently running Ant. Ignored if fork="no". Since Ant 1.6 this attribute can also be used to specify the path to the executable when using jikes, jvc, gcj or sj.

如果您只是在不指定任何外部编译器的情况下调用javac,则Ant将使用运行Ant的Java版本随附的编译器.从错误消息中可以明显看出,它使用的是Java 1.6编译器(其类文件的版本为50.0). Ant通常使用PATH环境变量中的java可执行文件运行.因此,请确保在PATH变量中指定的第一个Java目录是Java 1.8.

If you're just calling javac without specifying any external compiler, then Ant would use the compiler that comes with the Java version that is running Ant. And from the error message, it's clearly using the Java 1.6 compiler (for which classfiles have version 50.0). Ant normally runs using the java executable found in the PATH environment variable. So make sure that the first Java directory that is specified in the PATH variable is Java 1.8.

理想情况下,您应该将JAVA_HOME设置为Java 1.8的路径,并且PATH引用JAVA_HOME本身,以便它们都指向同一安装.

Ideally you should have JAVA_HOME set to the path of Java 1.8, and have PATH refer to JAVA_HOME itself so that both point to the same installation.

JAVA_HOME -> /path_to_jdk1.8
PATH -> %JAVA_HOME%;...;/path_to_some_other_jdk

这篇关于错误的类文件使ant构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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