English 中文(简体)
Ant taskdef需要什么类路径?
原标题:What classpath do I need for an Ant taskdef?
  • 时间:2010-10-14 12:37:31
  •  标签:
  • ant
  • taskdef

I m new to Ant. Can someone please tell me what value to put for the classpathref for taskdef? Will it be the path of the class file? If yes can an example be given because I tried that and its not working for me.

最佳回答

In the taskdef, the classpathref should be a reference to a previously defined path. The path should include a jar archive that holds the class implementing the task, or it should point to the directory in the file system that is the root of the class hierarchy. This would not be the actual directory that holds your class if your class resides in a package.

这是一个例子。

我的任务.java:

package com.x.y.z;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class MyTask extends Task
{
    // The method executing the task
    public void execute() throws BuildException {
        System.out.println( "MyTask is running" );
    }
}

Note that the package name is com.x.y.z, so when deployed - lets say the classes are put under a directory called classes - we might see the class here in the file system:

$ ls classes/com/x/y/z
MyTask.class

下面是一个使用该任务的简单build.xml:

<project name="MyProject" basedir=".">

<path id="my.classes">
    <pathelement path="${basedir}/classes" />
</path>
<taskdef name="mytask" classpathref="my.classes" classname="com.x.y.z.MyTask"/>
<mytask />

</project>

请注意,classpathref给定的点位于class目录——类层次结构的根目录。

运行时,我们得到:

$ ant
Buildfile: .../build.xml
   [mytask] MyTask is running

您可以使用显式<code>classpath</code>而不是classpathref来执行类似操作,例如:

<property name="my.classes" value="${basedir}/classes" />
<taskdef name="mytask" classpath="${my.classes}" classname="com.x.y.z.MyTask"/>
问题回答

暂无回答




相关问题
i want to continously run my java threads

I am running my java application where i have used threads... i am running this application using ant command on the terminal.. But when i close my terminal or press ctrl+c,then java program which was ...

Subant targets instead of ant

I m having a problem with subant and have no ideas any more. Can anyone help? Using Ant to replace some strings for other (i.e Productname and Version for "Foo" and "1.2") I used ...

java ant buildfile for project with dependencies

I am new to ant, but am trying to create an ant script that builds my current proeject with another project as a dependency. I have the ant script building my current project, but am unsure how to add ...

Building Apache Hive - impossible to resolve dependencies

I am trying out the Apache Hive as per http://wiki.apache.org/hadoop/Hive/GettingStarted and am getting this error from Ivy: Downloaded file size doesn t match expected Content Length for http://...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签