Javac 1.7 版无法为目标 1.7 构建 [英] Javac version 1.7 not able to build for target 1.7

查看:20
本文介绍了Javac 1.7 版无法为目标 1.7 构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Linux Mint 系统上使用 Sun Java JDK 1.7.0_17 编译 Java 代码,但我遇到了这个问题.

I am trying to compile Java code, with Sun Java JDK 1.7.0_17, on a Linux Mint system, but I'm getting this problem.

$ javac  -version -target 1.7 
javac 1.7.0_17
javac: invalid target release: 1.7

-target 1.6 也不起作用.Target 1.5 有效,但我遇到了版本问题,

-target 1.6 doesn't work either. Target 1.5 works, but I get a version problem as such,

$ javac  -version -target 1.5 HelloWorld.java 
javac 1.7.0_17
HelloWorld.java:2: cannot access java.lang.Object
bad class file: /usr/lib/jvm/jdk1.7.0_17/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
class HelloWorldApp {
^
1 error

在 sun java 目录之外是否有可用的 java 目标列表?

Is there somewhere a list of available java targets outside of the sun java directories?

我没有指定 ClassPath 或 Javahome,设置它们也无济于事.jcontrol 没有帮助.我也试过 1.7.0_15,结果相似.

I have no ClassPath or Javahome specified, and setting them doesn't help. jcontrol doesn't help. I have also tried with 1.7.0_15, with similar results.

推荐答案

我解决了一个涉及 Ubuntu、Netbeans 和两个 JDK:openJDK 和 oracleJDK 的类似问题.有问题的(旧的和不相关的)文件最终位于/usr/java/packages 中并被简单地删除.

I chased down a similar issue involving Ubuntu, Netbeans and two JDK's: openJDK and oracleJDK. The offending (old and irrelevant) files were eventually located in /usr/java/packages and simply deleted.

我收到了:

# javac -version hello.java
javac 1.7.0_21
hello.java:3: cannot access java.lang.Object
bad class file: /usr/lib/jvm/java-7-oracle/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class hello {
       ^
1 error

更重要的是,我通过以下方式找到了有问题的文件:

More importantly, I located the offending files with:

# javac -verbose -version hello.java

-verbose 选项列出了类文件的搜索路径.

The -verbose option lists the search path for class files.

我在调查期间探索的其他领域包括:

Other areas explored during my investigation were:

  • 环境变量JAVA_HOME的值与#echo $JAVA_HOME
  • 环境变量PATH与#echo $JAVA_HOME的值
  • 环境变量CLASSPATH的值与#echo $JAVA_HOME
  • 带有 #update-alternatives --config javac
  • 的更新替代方案
  • 带有 #galternatives 的更新替代方案
  • Netbeans 使用的 JDK 设置在/usr/local/netbeans-7.3/etc/netbeans.conf 中,带有 netbeans_jdkhome= 开关.请注意,此开关会覆盖 update-alternatives
  • the value of environment variable JAVA_HOME with #echo $JAVA_HOME
  • the value of environment variable PATH with #echo $JAVA_HOME
  • the value of environment variable CLASSPATH with #echo $JAVA_HOME
  • the update-alternatives with #update-alternatives --config javac
  • the update-alternatives with #galternatives
  • the JDK used by Netbeans set in /usr/local/netbeans-7.3/etc/netbeans.conf with the netbeans_jdkhome= switch. Note that this switch overrides update-alternatives

这篇关于Javac 1.7 版无法为目标 1.7 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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