繁体   English   中英

Java类主要版本

[英]Java class major version

我正在使用sun / oracle jdk 1.6.0_32,并且javac编译器似乎为目标1.5 jvm(而不是1.6)创建类文件。 它不会接受-source 1.6 -target 1.6。 用javap查看生成的类文件显示了一个主要版本:49,而不是我所期望的50。 Eclipse Indigo正确创建了与1.6兼容的主版本为50的类文件。在Eclipse中使用ant 1.8.2时,我首先注意到了这一点,并且无法将source或target属性设置为1.6。 我做错什么了吗?

附录

我只安装了1个jdk(1.6.0_32)。 从命令行我得到以下内容。

ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ ls -al
total 8
drwxr-xr-x 2 ken ken 4096 2012-06-28 16:50 .
drwxr-xr-x 3 ken ken 4096 2012-06-28 16:46 ..
ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ javac -d /home/ken/projects/simpleHelloWorld/bin -version /home/ken/projects/simpleHelloWorld/src/com/kwcons/HelloWorld.java
javac 1.6.0_32
ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ ls -al
total 12
drwxr-xr-x 2 ken ken 4096 2012-06-28 16:50 .
drwxr-xr-x 3 ken ken 4096 2012-06-28 16:46 ..
-rw-r--r-- 1 ken ken  441 2012-06-28 16:50 HelloWorld.class
ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ /usr/lib/jvm/java-6-sun/bin/javap -verbose HelloWorld |grep major
  major version: 49
ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ 

如果使用-source和-target,这就是我得到的。

ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ javac -d /home/ken/projects/simpleHelloWorld/bin -version -source 1.6 -target 1.6 /home/ken/projects/simpleHelloWorld/src/com/kwcons/HelloWorld.java
javac 1.6.0_32
javac: invalid source release: 1.6
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files
  -cp <path>                 Specify where to find user class files
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -d <directory>             Specify where to place generated class files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -version                   Version information
  -help                      Print a synopsis of standard options
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system

ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$ 

我从eclipse中的ant得到了相同的输出。

试试这个1)在ant脚本中指定jdk版本

2)在“编译”目标中编写以下javac目标,

runtime-libs ::它将指向您的项目lib目录。 在属性中声明。

<javac
bootclasspath="${runtime-libs}/rt.jar"
target="1.6"
source="1.6"
includeJavaRuntime="false"
includeAntRuntime="false"
debug="yes"
destdir="${build-dir}">
<classpath refid="project.class.path"/>
<src path="${code}"/>
</javac>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM