我有一个使用Ant Task的Ant脚本(我使用这个Task来执行QVTo转换)。
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>我在Java中用来执行Ant脚本的代码如下:
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脚本,就不会有任何问题,因为这个Task在Eclipse首选项中默认定义为Ant->Runtime->Tasks。
问题可能是在Java代码中执行的Ant脚本不是“在与项目相同的JRE中运行”。
我在plugin.xml中定义了Ant Task,它在类路径中运行Eclipse Application,也是作为一个扩展:
<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>有人知道我该如何解决我的问题吗?
提前感谢并致以问候。
发布于 2017-07-14 01:08:49
缺少Apache IVY库,请从此处- apache下载该库,然后将jar复制到ant lib目录中并添加到类路径中。
Ant下载jar并安装Ant(例如,C:\Apps\Tools\apache-ant-1.9).
发布于 2017-07-14 08:09:30
你能试着换一下吗?
发自:
<taskdef name="http://www.eclipse.org/qvt/1.0.0/Operational:transformation" classname="org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTask">至:
<taskdef name="transformation" classname="org.eclipse.m2m.internal.qvt.oml.runtime.ant.QvtoAntTransformationTask">并删除transformation任务/元素的名称空间前缀。
https://stackoverflow.com/questions/45085884
复制相似问题