Classpath for taskdef?

后端 未结 2 1756
死守一世寂寞
死守一世寂寞 2021-02-20 04:35

I am defining a new task in Ant. I exported it as a jar and added to my buildfile:


The pro

相关标签:
2条回答
  • 2021-02-20 05:13

    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 讨论(0)
  • 2021-02-20 05:28

    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>
    
    0 讨论(0)
提交回复
热议问题