0

私はsun/oracle jdk 1.6.0_32を使用していますが、javacコンパイラは1.6ではなくターゲット1.5jvmのクラスファイルを作成しているようです。-source 1.6-target1.6は受け入れられません。生成されたクラスファイルをjavapで見ると、メジャーバージョンが表示されます。予想どおり50ではなく49です。Eclipse Indigoは、メジャーバージョンが50の1.6準拠のクラスファイルを正しく作成します。Eclipseでant 1.8.2を使用しているときに最初に気づき、ソースまたはターゲットの属性を1.6に設定できませんでした。私が間違っていることはありますか?

補遺

インストールされているjdk(1.6.0_32)は1つだけです。コマンドラインから次のようになります。

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から同じ出力が得られます。

4

1 に答える 1

0

これを試してください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>
于 2012-06-28T04:46:13.047 に答える