Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java类主要版本_Java_Eclipse_Ant_Jvm - Fatal编程技术网

Java类主要版本

Java类主要版本,java,eclipse,ant,jvm,Java,Eclipse,Ant,Jvm,我正在使用sun/OracleJDK1.6.0_32,javac编译器似乎为目标1.5JVM而不是1.6创建类文件。它将不接受-source 1.6-target 1.6。用javap查看生成的类文件显示了一个主要版本:49而不是我预期的50。EclipseIndigo正确地创建了主版本为50的1.6兼容类文件。我第一次注意到这一点是在eclipse中使用Ant1.8.2时,当时无法将源属性或目标属性设置为1.6。我做错什么了吗 附录 我只安装了1个jdk(1.6.032)。从命令行中,我得到以

我正在使用sun/OracleJDK1.6.0_32,javac编译器似乎为目标1.5JVM而不是1.6创建类文件。它将不接受-source 1.6-target 1.6。用javap查看生成的类文件显示了一个主要版本:49而不是我预期的50。EclipseIndigo正确地创建了主版本为50的1.6兼容类文件。我第一次注意到这一点是在eclipse中使用Ant1.8.2时,当时无法将源属性或目标属性设置为1.6。我做错什么了吗

附录

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

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$ 
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
JavaC1.6.0_32
javac:无效的源代码版本:1.6
用法:javac
可能的选择包括:
-g生成所有调试信息
-g:无生成调试信息
-g:{lines,vars,source}只生成一些调试信息
-nowarn不生成警告
-详细输出有关编译器正在执行的操作的消息
-弃用输出使用弃用API的源位置
-类路径指定查找用户类文件的位置
-cp指定查找用户类文件的位置
-sourcepath指定查找输入源文件的位置
-引导类路径覆盖引导类文件的位置
-extdirs覆盖已安装扩展的位置
-ENDORSEDIR覆盖已认可标准路径的位置
-d指定放置生成的类文件的位置
-编码指定源文件使用的字符编码
-源提供与指定版本的源兼容性
-目标生成特定VM版本的类文件
-版本信息
-帮助打印标准选项的概要
-X打印非标准选项的概要
-J直接传递到运行时系统
ken@kryten:~/projects/simpleHelloWorld/bin/com/kwcons$
我在eclipse中从ant获得了相同的输出。

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

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

运行时库::它将指向您的项目库目录。在属性中声明

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


您安装了多少份JDK副本?
javac-version
的输出是什么?我使用的是1.6.0_21,它完美地创建了1.6类。你考虑过提交一份bug报告吗?和Jonathan一样的问题-请发布“javac-version”的结果。我很难相信你真的得到了javac的Java6版本。我试过了,但是我得到了[javac]编译1个源文件到/home/ken/projects/simpleHelloWorld/bin[javac]javac:invalid target release:1.6我只有一个jdk(1.6.032),我相信它使用的是正确的javac。我刚刚在terminal中编译了这个文件,我得到了一个类文件,javap说它是主要版本:49我仍然在习惯这个协议。在命令提示符下运行命令“java-version”,并检查您的java版本是什么。