2

Ant XML ファイルをプログラムで実行する Eclipse プラグインを開発しています。Ant XML ファイル
を使用org.apache.tools.ant.helper.ProjectHelperImplして解析し、特定のターゲット (この場合は. 私の Ant XML ファイルは次のようになります。org.apache.tools.ant.Projecttest

<!-- 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

4

1 に答える 1