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_jdkhome=
开关在/usr/local/netbeans-7.3/etc/netbeans.conf中设置的Netbeans使用的JDK.请注意,此开关将覆盖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