问题描述
限时送ChatGPT账号..全部 -
我遵循此页面上最简单的说明:
http://ant.apache/manual/develop.html
但是,当我尝试执行目标main"时,在 netbeans 中出现此错误:
<块引用>taskdef class dec102012.MyAntTask 无法使用类加载器 AntClassLoader[] 找到
但是这个错误没有意义,因为我的扩展Task"的新 Java 类看起来像这样:
包 dec102012;导入 org.apache.tools.ant.BuildException;公共类 MyAntTask 扩展了 org.apache.tools.ant.Task{私人字符串味精;//执行任务的方法public void execute() 抛出 BuildException {System.out.println(msg);}//消息"属性的设置器公共无效setMessage(字符串味精){this.msg = msg;}}
我的 build.xml 中的相关部分如下所示:
<目标名称=主要"><mytask message="Hello World!MyVeryOwnTask 有效!"/></目标>
解决方案 问题是 Ant 类加载器需要知道 *.class 文件所在的位置.
一旦我将 build.xml 更改为如下所示:
<目标名称=主要"><mytask message="Hello World!MyVeryOwnTask 有效!"/></目标>
它起作用了(即它打印出 Hello World 消息).
All -
I'm following the most simplest instructions on this page:
http://ant.apache/manual/develop.html
However, when I try to execute the target "main" I get this error in netbeans:
taskdef class dec102012.MyAntTask cannot be found using the classloader AntClassLoader[]
But this error does not make sense because my new Java class that extends "Task" looks like this:
package dec102012;
import org.apache.tools.ant.BuildException;
public class MyAntTask extends org.apache.tools.ant.Task{
private String msg;
// The method executing the task
public void execute() throws BuildException {
System.out.println(msg);
}
// The setter for the "message" attribute
public void setMessage(String msg) {
this.msg = msg;
}
}
The relevant portion in my build.xml looks like:
<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="dec102012"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
解决方案
The problem is the Ant Classloader needs to know where the *.class file sits.
Once I changed the build.xml to look like:
<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="build/classes"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
it worked (i.e. it printed out the Hello World message).
这篇关于找不到 taskdef ant 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论