LoginSignup
0
0

More than 1 year has passed since last update.

【Eclipse, Ant】jre less than 1.8 is not supported への対応

Last updated at Posted at 2022-06-09

背景

  • 古いJava Antプロジェクトのビルドで発生
  • 実行環境も古い JRE で動いているため、古いバージョン(1.6)でビルドする必要があった

環境

  • Eclipse 2022
  • Java 6
  • Ant 1.10

Eclipse 設定

  • Eclipse (build.xml -> 構成 -> JRE)

ワークスペースと同じJREで実行 (jdk1.6 にしない)

  • Eclipse (build.xml -> 構成 -> クラスパス -> Antホーム)

デフォルトのまま

build.xml の設定

  • パラメータ設定
build.xml
	<property name="javac.source"  value="1.6"/>
	<property name="javac.target"  value="1.6"/>
	<property name="javac.compiler"  value="javac1.6"/>
	<!-- jdk6 の javac へのパス -->
	<property name="javac.executable"  value="c:/Program Files/Java/jdk1.6.0_45/bin/javac"/>
  • コンパイル設定 (環境に合わせて下さい)
    source, target, compiler, executable, fork の設定を入れる
build.xml
	<!-- compile -->
	<target name="compile" depends="clean">
		<mkdir dir="${build.class.dir}" />
		<javac destdir="${build.class.dir}"
			debug="on"
			deprecation="on"
			optimize="on"
			classpathref="build.classpath"
			includeAntRuntime="false"
			encoding="UTF-8"
			source="${javac.source}"
			target="${javac.target}"
			compiler="${javac.compiler}"
			executable="${javac.executable}"
			fork="true"
		>
			<src path="${build.src}" />
		</javac>
	</target>

ビルド

  • build.xml 右クリック -> 実行 -> Antビルド

ビルドしてできた class ファイルの Java のバージョン確認

該当クラスファイルがあるディレクトリで

$ javap -v <class名>
...
  minor version: 0
  major version: 50
...

major version:50 とあれば java 6 でビルドされています。

以上です、お疲れさまでした!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0