Antタスクを使用するAntスクリプトがあります(このタスクを使用してQVTo変換を実行しています)。AntタスクによるAntスクリプトのプログラムによる実行
のAntスクリプトは、次のいずれかです。
<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="default" xmlns:qvto="http://www.eclipse.org/qvt/1.0.0/Operational">
<target name="default">
<taskdef name="http://www.eclipse.org/qvt/1.0.0/Operational:transformation" classname="org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTask">
<classpath>
<pathelement location="${basedir}/libAnt/antTasks.jar"/>
</classpath>
</taskdef>
<qvto:transformation uri="platform:/resource/QVToTransformation/transforms/QVTTransformation.qvto">
<in uri="platform:/resource/QVToTransformation/In/In.ecp" />
<out uri="platform:/resource/QVToTransformation/Out/Out.uml" />
<trace uri="platform:/resource/QVToTransformation/Trace/trace.qvtotrace"
generate="true" incrementalUpdate="false" />
</qvto:transformation>
</target>
</project>
私はAntのスクリプトを実行するためにJavaで使用したコードは、次のいずれかです。
File AntFile = new File(this.getClass().getResource("qvto/AntQVTo.xml").getFile());
Project p = new Project();
p.setUserProperty(
"ant.file",
this.getClass().getResource("qvto/AntQVTo.xml").getFile()
);
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, AntFile);
p.executeTarget(p.getDefaultTarget());
問題、私は私のJavaコードを実行したときでありますAnt Taskが全く認識されないようですが、次のエラーが返されたときに返されます。
Exception in thread "AWT-EventQueue-0" C:\path\to\AntTask\AntQVTo.xml:5: Problem: failed to create task or type http://www.eclipse.org/qvt/1.0.0/Operational:transformation
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
EclipseでAntスクリプトを直接実行すると、このタスクはEclipseの環境設定でAnt-> Runtime-> Tasksにデフォルトで定義されているため、問題はありません。
Javaコード内で実行されるAntスクリプトが「プロジェクトと同じJREで実行」として実行されない可能性があります。
私はAntタスクは、拡張機能としても、クラスパスにEclipseのアプリケーションを実行するのplugin.xmlに定義されていることがあります。
<extension point="org.eclipse.ant.core.antTasks">
<antTask
class="org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTask"
eclipseRuntime="true"
headless="true"
library="libAnt/antTasks.jar"
name="transformation"
uri="http://www.eclipse.org/qvt/1.0.0/Operational"
/>
</extension>
誰もが、私は私の問題を解決することができる方法を知っていますか?
ありがとうございます。
あなたのAntスクリプトのどこにでも新しいタスクを 'taskdef'タスクで定義していますか? https://ant.apache.org/manual/Tasks/taskdef.htmlとhttps://ant.apache.org/manual/Tasks/typedef.html – CAustin
私はすでにtaskdefタグを追加していますが、警告メッセージ 'taskdef class org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTaskは、 クラスローダーAntClassLoader []'を使用して見つけることができません。同じメッセージで実行も失敗します。私は指していると思いますパスは正しくありますが、わかりません。 –
あなたが今追加した 'taskdef'を見てください。一つのこととして、名前やタスクはURLであってはいけません。jarファイル自体にアクセスできなければ、何が間違っているのか本当に言い切れません。ここでも、Antのtypedefのドキュメントを参照することをお勧めします。 – CAustin