LoginSignup
3
2

More than 5 years have passed since last update.

JDTを利用してビルドを行うAntビルドファイル

Posted at

概要

とあるプロジェクトで、EclipseのJDTによるビルドと同じバイナリを生成するAntビルドファイルが必要になったので、javacタスクで指定したオプションをメモしておくもの。

プロジェクトのオプション指定とJDT Core Batch Compilerのオプションの関係

EclipseのプロジェクトのプロパティーでJavaコンパイラーに関するオプションを指定できるが、JDT Core Batch Compilerのオプションとの関係は以下のとおり。

Eclipseオプション JDT Core Batch Compilerオプション 備考
生成されたクラス・ファイルに変数属性を追加
Add variable attributes to generated class files
-g:vars
生成されたクラス・ファイルに行番号属性を追加
Add line number attributes to generated class files
-g:lines
生成されたクラス・ファイルにソース・ファイル名を追加
Add source file name to generated class file
-g:source
未使用の(読み取られない)ローカル変数を保存
Preserve unused (never read) local variables
-preserveAllLocals
finallyブロックをインライン化
Inline finally blocks
-inlineJSR Java1.5以上は暗黙的に適用
メソッド・パラメーターの情報を保管
Store information about method parameters
-parameters Java8以上で使用可

Antビルドファイルのjavacタスクにおいて、-gコマンドラインスイッチはdebuglevel属性に、後はcompilerarg要素に設定する。
以下はEclipseのデフォルト設定(表の上から4つを全て適用)のjavacタスクの例。

build.xml
<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter"
  classpathref="build.lib"
  srcdir="${src.dir}" destdir="${dest.dir}"
  source="1.7" target="1.7"
  includeAntRuntime="false"
  debug="true" debuglevel="lines,vars,source">
  <compilerarg line="-preserveAllLocals" />
</javac>

(参考)JDT Core Batch Compilerで指定できるオプション

JDT Core Batch Compilerで指定できるオプションは、Help - Eclipse Platform
Java development user guide > Tasks > Compiling Java code > Using the batch compilerに詳細が書かれている。

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