开发者

Classpath for taskdef?

开发者 https://www.devze.com 2023-02-01 00:38 出处:网络
I am defining a new task in Ant. I exporte开发者_C百科d it as a jar and added to my buildfile: <taskdef classname=\"X\" classpath=\"Y.jar\"/>

I am defining a new task in Ant. I exporte开发者_C百科d it as a jar and added to my buildfile:

<taskdef classname="X" classpath="Y.jar"/>

The problem is that this fails at runtime. It tells me it didn't find the class. By adding the jar to the classpath, it is corrected.

My question is: Is there a way that I can refer to my jar from the Ant buildfile, without changing the classpath?


If you know the path of your jar, inside ant script you can define the classpath for your own task.

<taskdef name="myTaskName" classname="com.myorg.myclass">
  <classpath>
    <pathelement location="pathToMyJar.jar"/>
  </classpath>
</taskdef>


Yes. I'm assuming that you looked at the doc for taskdef, which just shows the task name and implementing class. However, taskdef subclasses typedef, and if you look at the doc for the latter you'll see that there's also a classpath attribute.

HOWEVER, using this attribute means that your ant scripts are tied to a particular environment; they aren't very portable. A far better approach is to pass the classpath into Ant, using the -lib invocation option.

0

精彩评论

暂无评论...
验证码 换一张
取 消