Ant XML ファイルをプログラムで実行する Eclipse プラグインを開発しています。Ant XML ファイル
を使用org.apache.tools.ant.helper.ProjectHelperImpl
して解析し、特定のターゲット (この場合は.
私の Ant XML ファイルは次のようになります。org.apache.tools.ant.Project
test
<!-- project class path -->
<path id="projectClassPath">
<fileset dir="${basedir}/jars">
<include name="**/*.jar" />
</fileset>
</path>
<!-- task definitions -->
<taskdef file="${basedir}/tasks.properties">
<classpath refid="projectClassPath" />
</taskdef>
<!-- test custom ant task -->
<target name="test" description="test target">
<customTask />
</target>
<!-- test echo -->
<target name="testEcho" description="test echo target">
<echo message="this is a test."/>
</target>
tasks.properties ファイルは次のようになります。
customTask=my.custom.task.CustomTask
プログラムでAntファイルを実行する私のJavaコード:
Project ant = new Project();
ProjectHelperImpl helper = new ProjectHelperImpl();
MyDefaultLogger log = new MyDefaultLogger();
ant.init();
helper.parse(ant, antXml);
log.setMessageOutputLevel(Project.MSG_VERBOSE);
ant.addBuildListener(log);
ant.executeTarget(testTarget);
ターゲットtest
を手動で実行しても問題test
ありませんが、ターゲットをプログラムで実行すると次のエラーが表示されます。
taskdef class my.custom.task.CustomTask cannot be found using the classloader AntClassLoader[]
project class path
を使用せずにプログラムでファイルを実行するtask definitions
と、test custom ant task
正常に実行されます。
私の推測では、Ant ファイルをプログラムで実行したときに、どういうわけかクラスパスが登録されなかったのでしょうか?
編集:
複数のターゲット名がターゲット名を にtest
変更しました。(クレジット: @smooth reggae)<!-- test echo -->
testEcho