ant内で新しいタスクを定義するコアタスク。
(org.apache.tools.ant.taskdefs.Taskdef extends Typedef)
属性 | 説明 | 更新日 |
---|---|---|
name="タスク名" | 新しいタスクの名前。 | |
classname="クラス名" | 新しいタスクのjavaプログラムのパッケージ名+クラス名。 | |
resource="ファイル名" | nameとclassnameのペアを記述したファイルを指定。 | |
classpath="パス" | classnameやresourceを検索するパスを指定。 | |
classpathref="ID" | <path id="ID">で定義したパスをclassnameやresourceの検索に使用する。 | |
loaderref="名前" | 複数のtaskdef(およびtypedef)で同じ名前のloaderrefが指定されていると、同一のクラスローダーが使われる。 →例 |
2009-01-13 |
<taskdef name="hoge" classname="jp.hishidama.Hoge"/> <target name="sample"> <hoge/> </target>
<?xml version="1.0" encoding="Shift_JIS"?> <project name="sample" default="default" basedir=".."> <path id="jcoverage"> <fileset dir="./lib"> <include name="*.jar"/> ←この中の1つがjcoverage.jar </fileset> </path> <taskdef classpathref="jcoverage" resource="tasks.properties"/> <target name="default"/> <target name="dummy"> <instrument> <fileset dir="./classes"> <include name="**/*.class"/> </fileset> </instrument> </target> </project>
jcoverage.jar内のルートディレクトリに、tasks.propertiesというファイルがある。この内容は
instrument=com.jcoverage.ant.InstrumentTask merge=com.jcoverage.ant.MergeTask report=com.jcoverage.ant.CoverageReportTask check=com.jcoverage.ant.CheckTask
といもの。
これにより、instrumentやmergeといったタスクが使えるようになる。
なお、instrumentタスクのボディー部に変なタグ(要素)を入れるとエラーになる(Eclipseでそういうbuild.xmlを読み込むと、読み込み自体がエラーになる)。
<instrument>
<fuge/>
<fileset dir="./classes">
<include name="**/*.class"/>
</fileset>
</instrument>
↓(Eclipseからこのbuild.xmlを実行するとエラー発生)
Buildfile: C:\bin\eclipse\workspace\sample\bin\build.xml
BUILD FAILED: file:C:/bin/eclipse/workspace/sample/bin/build.xml:16: The <instrument> task doesn't support the nested "fuge" element.
Total time: 201 milliseconds
ちなみに存在しているタスクだと別のエラー。
<instrument>
<classpath refid="jcoverage"/>
<fileset dir="./classes">
<include name="**/*.class"/>
</fileset>
</instrument>
↓(Eclipseからこのbuild.xmlを実行するとエラー発生)
Buildfile: C:\bin\eclipse\workspace\sample\bin\build.xml BUILD FAILED: Target `file:C:/bin/eclipse/workspace/sample/bin/build.xml:16: java.lang.NullPointerException' does not exist in this project. Total time: 201 milliseconds
ふつう、「Target `ターゲット名' does not exist in this project.
」はターゲットが見つからない時のエラーなんだけど、ターゲット名の部分が不可思議なエラーメッセージになってる…。